You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `llama_cpp_openai` module provides a lightweight implementation of an OpenAI API server on top of
5
+
Llama CPP models. This implementation is particularly designed for use with Microsoft AutoGen and includes support for function calls. The project is structured around the `llama_cpp_python` module and is aimed at facilitating the integration of AI models in applications using OpenAI clients or API.
6
+
7
+
## Project Structure
8
+
The project is organized into several key directories and files:
9
+
10
+
-**llama_cpp_openai**: Contains the core implementation of the API server.
11
+
-`__init__.py`: Initialization file for the module.
12
+
-`_api_server.py`: Defines the OpenAPI server, using FastAPI for handling requests.
13
+
-`_llama_cpp_functions_chat_handler.py`: Implements the `llama-2-functionary` chat handler that supports function calling.
14
+
15
+
-**examples**: Provides example scripts demonstrating the usage of the API server.
16
+
-`README.md`: Overview and description of example scripts.
17
+
-`autogen_basic.py`: Basic integration of AutoGen with Llama_CPP using the OpenAI API server.
18
+
-`autogen_functions.py`: Sets up an AutoGen chatbot with function calls capabilities.
19
+
-`basic.py`: Demonstrates the setup and start of an API server using the Llama library.
20
+
21
+
## Key Features
22
+
-**FastAPI Integration**: Utilizes FastAPI for efficient and easy-to-use API endpoints.
23
+
-**Llama Library Usage**: Leverages the Llama library for handling AI model interactions.
24
+
-**Function Call Support**: Includes capabilities for function calls in chatbot environments.
25
+
-**Examples for Quick Start**: Provides example scripts for easy understanding and implementation.
This module demonstrates the integration of Microsoft AutoGen with the Llama_CPP library and OpenAI API server. It includes scripts for setting up an AutoGen chatbot environment and starting a local OpenAI API server using the Llama library, which interfaces with OpenAI-like models.
5
+
6
+
## Files Description
7
+
1.**basic.py**:
8
+
- A simple script to set up and start an OpenAPI API server on top of Llama_CPP.
9
+
- Mimics the OpenAI API format for compatibility with existing OpenAPI clients.
10
+
- Requires specifying a model and configuration for the `Llama` class.
11
+
12
+
2.**autogen_basic.py**:
13
+
- Demonstrates the basic integration of Microsoft AutoGen with Llama_CPP using the OpenAI API server.
14
+
- Initialises a Llama instance with a GGUF model and starts a local OpenAI API server.
15
+
- Runs a basic AutoGen agent
16
+
17
+
3.**autogen_functions.py**:
18
+
- Sets up an AutoGen chatbot environment with function call capabilities.
19
+
- Utilizes a local OpenAI API server on top of Llama_CPP.
20
+
- Ideal for models supporting function calls, such as Trelis/Mistral-7B-Instruct-v0.1.
21
+
- Includes initialization of a Llama instance with a specific GPT-based model.
22
+
23
+
## Setup and Usage
24
+
1. In the project folder, run `poetry install`
25
+
2. Run the desired script:
26
+
- For setting up a simple API server: `poetry run python basic.py`
27
+
- For basic integration with AutoGen: `poetry run python autogen_basic.py`
28
+
- For a chatbot environment with function calls: `poetry run python autogen_functions.py`
This script sets up an AutoGen chatbot environment with function calls capabilities, using a local OpenAI API server on top of Llama_CPP and a model supporting function calls.
7
+
8
+
Process:
9
+
1. Initialize a Llama instance with a specific GPT-based model (e.g., Trelis/Mistral-7B-Instruct-v0.1 with function-calling capabilities), setting the model chat format to 'llama2_functionary' and enabling embeddings.
10
+
2. Start the local OpenAI API server on localhost at port 8000 using the Llama instance.
11
+
3. Configure the AutoGen setup to use the local API server, including custom function tools for 'weather' and 'traffic' information retrieval.
12
+
4. Create a UserProxyAgent representing a human user in the chat, with a system message indicating a human participant.
13
+
5. Create an AssistantAgent as a general-purpose chatbot, configured with the local Llama model and the ability to call custom functions.
14
+
6. The UserProxyAgent registers custom lambda functions for 'weather' and 'traffic' to simulate responses based on location and/or date.
15
+
7. Initiate a chat between the UserProxyAgent and the AssistantAgent with an initial message querying the weather in Tokyo.
16
+
17
+
This script exemplifies the integration of function-calling capabilities in a chatbot environment, showcasing how custom functionalities can be embedded within an AutoGen agent setup using a local OpenAI API server.
18
+
"""
19
+
20
+
llm=Llama(
21
+
# path to a gguf model supporting function calls (eg. HuggingFace's Trelis/Mistral-7B-Instruct-v0.1-function-calling-v2)
0 commit comments