diff --git a/docs/advanced/chat_functions/local.md b/docs/advanced/chat_functions/local.md index c10f7c981..fe8963c67 100644 --- a/docs/advanced/chat_functions/local.md +++ b/docs/advanced/chat_functions/local.md @@ -4,10 +4,10 @@ All request payloads below follow the [μEd API](https://mued.org/) `ChatRequest ## Run Unit Tests -You can run the unit tests using `pytest`: +You can run the unit tests using `pytest`. Run it from the repository root with `PYTHONPATH=.` set (as CI does), so that the `tests` and `src` packages resolve correctly: ```bash -pytest +PYTHONPATH=. pytest ``` ## Run the Chat Script @@ -46,12 +46,20 @@ docker run -e OPENAI_API_KEY={your key} -e OPENAI_MODEL={your LLM chosen model n docker run --env-file .env -it --name my-lambda-container -p 8080:8080 llm_chat ``` -This will start the chat function and expose it on port `8080` and it will be open to be curl: +This will start the chat function and expose the chat API on port `8080`, ready to be curled: ```bash -curl --location 'http://localhost:8080/2015-03-31/functions/function/invocations' \ +curl --location 'http://localhost:8080/chat' \ --header 'Content-Type: application/json' \ ---data '{"body":"{\"messages\": [{\"role\": \"USER\", \"content\": \"hi\"}]}"}' +--header 'X-Api-Version: 0.1.0' \ +--data '{"messages": [{"role": "USER", "content": "hi"}]}' +``` + +Health check: + +```bash +curl --location 'http://localhost:8080/chat/health' \ +--header 'X-Api-Version: 0.1.0' ``` ### Call Docker Container @@ -69,9 +77,11 @@ python tests/manual_agent_requests.py POST URL: ```bash -http://localhost:8080/2015-03-31/functions/function/invocations +http://localhost:8080/chat ``` +Requests may include an `X-Api-Version: 0.1.0` header. + Minimal body — only the required `messages` field: ```JSON diff --git a/docs/advanced/chat_functions/quickstart.md b/docs/advanced/chat_functions/quickstart.md index 1de3111c7..f9986cb61 100644 --- a/docs/advanced/chat_functions/quickstart.md +++ b/docs/advanced/chat_functions/quickstart.md @@ -22,7 +22,7 @@ Per the μEd `ChatRequest` schema, **only `messages` is required** — `conversa - For new functions: use the template repo [chat-function-boilerplate](https://github.com/lambda-feedback/chat-function-boilerplate) via *Use this template > Create a new repository*, choosing the `Lambda Feedback` organisation as the owner. **Make sure the new repository is set to public (it needs access to organisation secrets and GitHub deployment protection rules)**. - For existing functions: please make your changes on a new separate branch -2. Add your LLM credentials to a `.env` file in the root of the repository. OpenAI, Google AI and Ollama are supported out of the box: +2. Add your LLM credentials to a `.env` file in the root of the repository. OpenAI, Google AI, OpenRouter, Azure OpenAI and Ollama are supported out of the box: ```bash # If you use OpenAI: @@ -33,6 +33,11 @@ Per the μEd `ChatRequest` schema, **only `messages` is required** — `conversa GOOGLE_AI_API_KEY GOOGLE_AI_MODEL + # If you use OpenRouter: + OPENROUTER_API_KEY + OPENROUTER_MODEL + OPENROUTER_BASE_URL + # If you use Ollama: OLLAMA_MODEL OLLAMA_BASE_URL @@ -54,9 +59,11 @@ Per the μEd `ChatRequest` schema, **only `messages` is required** — `conversa 4. **`src/agent/context.py`**: converts the μEd API `context` and `user` dictionaries into the prompt text given to the LLM. - 5. Update the `config.json` file with the name of the chat function. + 5. **`index.py`**: the entrypoint of the deployed function. It registers the `chat` and `chat health` handlers from `src/module.py` with `lf_toolkit`'s server. + + 6. Update the `config.json` file with the name of the chat function. - 6. Please add a `README.md` file (and update `docs/`) to describe the use and behaviour of your chatbot. + 7. Please add a `README.md` file (and update `docs/`) to describe the use and behaviour of your chatbot. ## Request and response schema @@ -154,10 +161,10 @@ Expected response: ## Testing your changes -Changes can be tested locally by running the pipeline tests using: +Changes can be tested locally by running the pipeline tests from the repository root with `PYTHONPATH=.` set (as CI does): ```bash -pytest +PYTHONPATH=. pytest ``` [Running and Testing Chat Functions Locally](local.md){ .md-button }