-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganize and add new services for propmt
- Loading branch information
Showing
39 changed files
with
866 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Agenta Services | ||
|
||
This directory contains various versions of Agenta's LLM services, each offering distinct capabilities and interfaces for language model interactions. | ||
|
||
## Service Overview | ||
|
||
### Legacy Services | ||
- **completion-old-sdk**: Original completion service (as in current release) | ||
- **chat-old-sdk**: Original chat service (as in current release) | ||
|
||
### New Services | ||
All services with "new-sdk" utilize the modified SDK, which includes these changes: | ||
- Configuration is now nested under `agenta_config` in the request body (no longer flattened) | ||
- Implements the stateless SDK (no interface changes, but may introduce future issues in cloud deployment due to lack of testing) | ||
|
||
We've created two versions of each new service: | ||
1. Original logic with new SDK: | ||
- completion-new-sdk | ||
- chat-new-sdk | ||
2. New prompt object and updated logic: | ||
- completion-new-sdk-prompt | ||
- chat-new-sdk-prompt | ||
|
||
## Service Components | ||
|
||
Each service includes: | ||
- Docker configuration (`docker-compose.yml`) | ||
- REST API documentation (`.rest` files) | ||
- Implementation code (`_app.py`) | ||
|
||
## Usage | ||
|
||
For usage examples and API details, refer to the `.rest` files in each service's directory. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
### Test chat-new-sdk-prompt | ||
POST http://localhost/chat-new-sdk-prompt/chat | ||
Content-Type: application/json | ||
|
||
{ | ||
"inputs": { | ||
"message": "What is the capital of France?" | ||
} | ||
} | ||
|
||
### Test chat configuration with prompt | ||
POST http://localhost/chat-new-sdk-prompt/configure | ||
Content-Type: application/json | ||
|
||
{ | ||
"model": "gpt-3.5-turbo", | ||
"temperature": 0.7, | ||
"max_tokens": 100, | ||
"prompt": { | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are a helpful assistant specializing in geography." | ||
} | ||
], | ||
"template_format": "fstring", | ||
"response_format": { | ||
"type": "text" | ||
}, | ||
"tools": null, | ||
"tool_choice": "auto" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
services: | ||
chat-new-sdk-prompt: | ||
build: . | ||
volumes: | ||
- .:/app | ||
- ../../agenta-cli:/agenta-cli | ||
environment: | ||
- AGENTA_UNAUTHORIZED_EXECUTION_ALLOWED=True | ||
- AGENTA_HOST=http://host.docker.internal | ||
networks: | ||
- agenta-network | ||
labels: | ||
- "traefik.http.routers.chat-new-sdk-prompt.rule=PathPrefix(`/chat-new-sdk-prompt/`)" | ||
- "traefik.http.routers.chat-new-sdk-prompt.entrypoints=web" | ||
- "traefik.http.middlewares.chat-new-sdk-prompt-strip.stripprefix.prefixes=/chat-new-sdk-prompt" | ||
- "traefik.http.middlewares.chat-new-sdk-prompt-strip.stripprefix.forceslash=true" | ||
- "traefik.http.routers.chat-new-sdk-prompt.middlewares=chat-new-sdk-prompt-strip" | ||
- "traefik.http.services.chat-new-sdk-prompt.loadbalancer.server.port=80" | ||
- "traefik.http.routers.chat-new-sdk-prompt.service=chat-new-sdk-prompt" | ||
|
||
networks: | ||
agenta-network: | ||
external: true |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from typing import Annotated, Any, Dict, List | ||
|
||
import agenta as ag | ||
from agenta.sdk.assets import supported_llm_models | ||
from pydantic import BaseModel, Field | ||
import os | ||
# Import mock if MOCK_LLM environment variable is set | ||
if os.getenv("MOCK_LLM", True): | ||
from mock_litellm import MockLiteLLM | ||
|
||
litellm = MockLiteLLM() | ||
else: | ||
import litellm | ||
|
||
litellm.drop_params = True | ||
litellm.callbacks = [ag.callbacks.litellm_handler()] | ||
|
||
SYSTEM_PROMPT = "You have expertise in offering technical ideas to startups." | ||
|
||
ag.init() | ||
|
||
|
||
class MyConfig(BaseModel): | ||
temperature: float = Field(default=0.2, le=1, ge=0) | ||
model: Annotated[str, ag.MultipleChoice(choices=supported_llm_models)] = Field( | ||
default="gpt-3.5-turbo" | ||
) | ||
max_tokens: int = Field(default=-1, ge=-1, le=4000) | ||
prompt_system: str = Field(default=SYSTEM_PROMPT) | ||
|
||
|
||
@ag.instrument(spankind="llm") | ||
async def llm_call(messages: List[Dict[str, Any]], maxtokens): | ||
config = ag.ConfigManager.get_from_route(schema=MyConfig) | ||
chat_completion = await litellm.acompletion( | ||
model=config.model, | ||
messages=messages, | ||
temperature=config.temperature, | ||
max_tokens=maxtokens, | ||
) | ||
token_usage = chat_completion.usage.dict() | ||
return { | ||
"usage": token_usage, | ||
"message": chat_completion.choices[0].message.content, | ||
"cost": litellm.cost_calculator.completion_cost( | ||
completion_response=chat_completion, model=config.model | ||
), | ||
} | ||
|
||
|
||
@ag.route("/", config_schema=MyConfig) | ||
@ag.instrument() | ||
async def chat(inputs: ag.MessagesInput = ag.MessagesInput()) -> Dict[str, Any]: | ||
config = ag.ConfigManager.get_from_route(schema=MyConfig) | ||
messages = [{"role": "system", "content": config.prompt_system}] + inputs | ||
max_tokens = config.max_tokens if config.max_tokens != -1 else None | ||
response = await llm_call( | ||
messages=messages, | ||
maxtokens=max_tokens, | ||
) | ||
return { | ||
"message": response["message"], | ||
"usage": response.get("usage", None), | ||
"cost": response.get("cost", None), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
services: | ||
chat-new-sdk: | ||
build: . | ||
volumes: | ||
- .:/app | ||
- ../../agenta-cli:/agenta-cli | ||
environment: | ||
- AGENTA_UNAUTHORIZED_EXECUTION_ALLOWED=True | ||
- AGENTA_HOST=http://host.docker.internal | ||
networks: | ||
- agenta-network | ||
labels: | ||
- "traefik.http.routers.chat-new-sdk.rule=PathPrefix(`/chat-new-sdk/`)" | ||
- "traefik.http.routers.chat-new-sdk.entrypoints=web" | ||
- "traefik.http.middlewares.chat-new-sdk-strip.stripprefix.prefixes=/chat-new-sdk" | ||
- "traefik.http.middlewares.chat-new-sdk-strip.stripprefix.forceslash=true" | ||
- "traefik.http.routers.chat-new-sdk.middlewares=chat-new-sdk-strip" | ||
- "traefik.http.services.chat-new-sdk.loadbalancer.server.port=80" | ||
- "traefik.http.routers.chat-new-sdk.service=chat-new-sdk" | ||
|
||
networks: | ||
agenta-network: | ||
external: true |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
### Test completion-new-sdk-prompt | ||
POST http://localhost/completion-new-sdk-prompt/generate | ||
Content-Type: application/json | ||
|
||
{ | ||
"inputs": { | ||
"country": "France" | ||
} | ||
} | ||
|
||
### Test completion configuration with prompt | ||
POST http://localhost/completion-new-sdk-prompt/configure | ||
Content-Type: application/json | ||
|
||
{ | ||
"model": "gpt-3.5-turbo", | ||
"temperature": 0.7, | ||
"max_tokens": 100, | ||
"prompt": { | ||
"messages": [ | ||
{ | ||
"role": "system", | ||
"content": "You are a helpful assistant." | ||
}, | ||
{ | ||
"role": "user", | ||
"content": "What is the capital of {country}?" | ||
} | ||
], | ||
"template_format": "fstring", | ||
"response_format": { | ||
"type": "text" | ||
}, | ||
"tools": null, | ||
"tool_choice": "auto" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM python:3.10-slim | ||
|
||
ARG ROOT_PATH=/ | ||
ENV ROOT_PATH=${ROOT_PATH} | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
|
||
RUN pip install --upgrade pip \ | ||
&& pip install --no-cache-dir agenta openai python-dotenv uvicorn "litellm>=1.0,<2.0" google-generativeai | ||
|
||
# Add agenta-cli to PYTHONPATH so it can find the local agenta package | ||
ENV PYTHONPATH=/agenta-cli:$PYTHONPATH | ||
|
||
EXPOSE 80 | ||
|
||
CMD ["./entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM python:3.10-slim | ||
|
||
ARG ROOT_PATH=/ | ||
ENV ROOT_PATH=${ROOT_PATH} | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
|
||
RUN pip install --upgrade pip \ | ||
&& pip install --no-cache-dir openai python-dotenv uvicorn "litellm>=1.0,<2.0" google-generativeai \ | ||
&& pip install --no-cache-dir --pre agenta | ||
|
||
EXPOSE 80 | ||
|
||
CMD ["./entrypoint.sh"] |
Oops, something went wrong.