Skip to content

Commit

Permalink
Add generate endpoint for llm-vscode (#1074)
Browse files Browse the repository at this point in the history
* Add generate endpoint for llm-vscode

* v1.4.41
  • Loading branch information
Josh-XT authored Nov 29, 2023
1 parent 5e8d0c0 commit 2ab9d03
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
10 changes: 10 additions & 0 deletions agixt/Models.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,13 @@ class User(BaseModel):
email: str
role: str
api_key: str


class GenerateModel(BaseModel):
inputs: str
parameters: dict


class GenerateResponse(BaseModel):
details: dict
generated_text: str
47 changes: 47 additions & 0 deletions agixt/endpoints/Completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from Models import (
Completions,
EmbeddingModel,
GenerateModel,
GenerateResponse,
)

app = APIRouter()
Expand Down Expand Up @@ -144,3 +146,48 @@ async def embedding(
"object": "list",
"usage": {"prompt_tokens": tokens, "total_tokens": tokens},
}


@app.post(
"/api/v1/{agent_name}/generate",
tags=["Completions"],
dependencies=[Depends(verify_api_key)],
)
async def generate_text(
generate: GenerateModel,
agent_name: str,
user=Depends(verify_api_key),
authorization: str = Header(None),
):
ApiClient = get_api_client(authorization=authorization)
agent = Interactions(agent_name=agent_name, user=user, ApiClient=ApiClient)
response = await agent.run(
user_input=generate.inputs, prompt="Custom Input", **generate.parameters
)
tokens = get_tokens(response)
details = {
"best_of_sequences": [
{
"finish_reason": "length",
"generated_text": response,
"generated_tokens": tokens,
"prefill": [{"id": 0, "logprob": -0.34, "text": response}],
"seed": 42,
"tokens": [
{"id": 0, "logprob": -0.34, "special": False, "text": response}
],
"top_tokens": [
[{"id": 0, "logprob": -0.34, "special": False, "text": response}]
],
}
],
"finish_reason": "length",
"generated_tokens": tokens,
"prefill": [{"id": 0, "logprob": -0.34, "text": response}],
"seed": 42,
"tokens": [{"id": 0, "logprob": -0.34, "special": False, "text": response}],
"top_tokens": [
[{"id": 0, "logprob": -0.34, "special": False, "text": response}]
],
}
return GenerateResponse(details=details, generated_text=response)
2 changes: 1 addition & 1 deletion agixt/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.4.40
v1.4.41

0 comments on commit 2ab9d03

Please sign in to comment.