1 line
6.7 KiB
JSON
1 line
6.7 KiB
JSON
{"repo": "abascope/llm-python", "files": {"README.md": {"2436d85d1b6099868dcb5f9b285f004d9a263268": {"t": 1785746718.8884234, "n": 6443, "h": "98f1572a4371fa8b", "c": "# Agent Voice Response - OpenAI Integration\n\n[](https://discord.gg/DFTU69Hg74)\n[](https://github.com/agentvoiceresponse/avr-llm-openai)\n[](https://hub.docker.com/r/agentvoiceresponse/avr-llm-openai)\n[](https://ko-fi.com/agentvoiceresponse)\n\nThis repository showcases the integration between **Agent Voice Response** and **OpenAI**. The application leverages OpenAI's powerful language model to process text input from users, providing intelligent, context-aware responses that enhance the virtual agent's capabilities.\n\n## Prerequisites\n\nTo set up and run this project, you will need:\n\n1. **Node.js** and **npm** installed.\n2. An **OpenAI API key**.\n\n## Setup\n\n### 1. Clone the Repository\n\n```bash\ngit clone https://github.com/agentvoiceresponse/avr-llm-openai.git\ncd avr-llm-openai\n```\n\n### 2. Install Dependencies\n\n```bash\nnpm install\n```\n\n### 3. Configure Environment Variables\n\nCreate a `.env` file in the root of the project to store your API keys and configuration. You will need to add the following variables:\n\n```bash\nOPENAI_API_KEY=your_openai_api_key\nPORT=6002\nOPENAI_MODEL=gpt-3.5-turbo # Optional, defaults to gpt-3.5-turbo\nOPENAI_BASEURL=your_custom_base_url # Optional, for custom OpenAI API endpoints\nSYSTEM_PROMPT=your_system_prompt # Optional, defaults to \"You are a helpful assistant.\"\nOPENAI_TEMPERATURE=0.0 # Optional, controls randomness (0.0-1.0), defaults to 0.0\nOPENAI_MAX_TOKENS=100 # Optional, controls response length, defaults to 100\n```\n\nReplace `your_openai_api_key` with your actual OpenAI API key.\n\n#### Using DeepSeek\n\nTo use DeepSeek instead of OpenAI's models, set the following environment variables:\n\n```bash\nOPENAI_BASEURL=https://api.deepseek.com\nOPENAI_MODEL=deepseek-chat # or another DeepSeek model name\nOPENAI_API_KEY=your_deepseek_api_key\n```\n\nMake sure to replace `your_deepseek_api_key` with your actual DeepSeek API key. DeepSeek models are compatible with the OpenAI API format, so no additional code changes are required.\n\n### 4. Running the Application\n\nStart the application by running the following command:\n\n```bash\nnode index.js\n```\n\nThe server will start on the port defined in the environment variable (default: 6002).\n\n## How It Works\n\nThe **Agent Voice Response** system integrates with OpenAI to provide intelligent text-based responses to user queries. The server receives text input from users, forwards it to OpenAI's API, and then returns the model's response to the user in real time using Server-Sent Events (SSE). This allows the virtual agent to simulate conversational abilities, improving the overall user experience.\n\n### Key Components\n\n- **Express.js Server**: The server handles incoming requests from clients and sends them to OpenAI's API for processing.\n- **OpenAI API Integration**: The application sends text queries to OpenAI and receives generated responses, which are relayed back to the user.\n- **Tool Integration**: The system supports OpenAI function calling, allowing the AI to use custom tools for enhanced capabilities.\n- **Response Streaming**: Responses are streamed back to the client in real-time using Server-Sent Events.\n\n### Tool Integration\n\nThe application supports OpenAI function calling through a custom tool system. Tools are loaded dynamically and can be extended to provide additional capabilities to the AI:\n\n1. **Tool Loading**: Tools are loaded at runtime using the `loadTools()` function.\n2. **Tool Handlers**: Each tool has a corresponding handler function that executes when called by the AI.\n3. **Error Handling**: The system includes robust error handling for tool execution.\n\n## API Endpoints\n\n### POST `/prompt-stream`\n\nThis endpoint accepts a JSON payload containing the user's messages and a UUID, and returns a streamed response generated by OpenAI.\n\n**Request Body:**\n```json\n{\n \"messages\": [\n {\"role\": \"user\", \"content\": \"Hello, how are you?\"}\n ],\n \"uuid\": \"user-session-id\"\n}\n```\n\n**Response:**\nThe response is streamed as Server-Sent Events (SSE) with JSON objects containing:\n- `type`: The type of content (e.g., \"text\")\n- `content`: The actual content from OpenAI or tool responses\n\n## Customizing the Application\n\n### Environment Variables\n\nYou can customize the application behavior using the following environment variables:\n\n- `OPENAI_API_KEY`: Your OpenAI API key (required)\n- `PORT`: The port on which the server will listen (default: 6002)\n- `OPENAI_MODEL`: The OpenAI model to use (default: gpt-3.5-turbo)\n- `OPENAI_BASEURL`: Custom base URL for OpenAI API (optional)\n- `SYSTEM_PROMPT`: Custom system prompt for the AI (optional)\n- `OPENAI_TEMPERATURE`: Controls randomness in responses (0.0-1.0, default: 0.0)\n- `OPENAI_MAX_TOKENS`: Controls the maximum length of the response (default: 100)\n\n### Adding Custom Tools\n\nTo add custom tools to the application:\n\n1. Create a new tool definition in the `tools` directory\n2. Implement the corresponding handler function\n\n## Error Handling\n\nThe application includes comprehensive error handling for:\n- Missing required parameters\n- OpenAI API errors\n- Tool execution errors\n\nAll errors are logged to the console and appropriate error messages are returned to the client.\n\n## Support & Community\n\n* **GitHub:** [https://github.com/agentvoiceresponse](https://github.com/agentvoiceresponse) - Report issues, contribute code.\n* **Discord:** [https://discord.gg/DFTU69Hg74](https://discord.gg/DFTU69Hg74) - Join the community discussion.\n* **Docker Hub:** [https://hub.docker.com/u/agentvoiceresponse](https://hub.docker.com/u/agentvoiceresponse) - Find Docker images.\n* **Wiki:** [https://wiki.agentvoiceresponse.com/en/home](https://wiki.agentvoiceresponse.com/en/home) - Project documentation and guides.\n\n\n## Support AVR\n\nAVR is free and open-source. If you find it valuable, consider supporting its development:\n\n<a href=\"https://ko-fi.com/agentvoiceresponse\" target=\"_blank\"><img src=\"https://ko-fi.com/img/githubbutton_sm.svg\" alt=\"Support us on Ko-fi\"></a>\n\n## License\n\nMIT License - see the [LICENSE](LICENSE.md) file for details.#\u0000 \u0000l\u0000l\u0000m\u0000-\u0000p\u0000y\u0000t\u0000h\u0000o\u0000n\u0000\r\u0000\n\u0000"}}}} |