forked from Significant-Gravitas/AutoGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/llm data structs (Significant-Gravitas#3486)
* Organize all the llm stuff into a subpackage * Add structs for interacting with llms
- Loading branch information
Showing
9 changed files
with
122 additions
and
14 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
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 dataclasses import dataclass, field | ||
from typing import List, TypedDict | ||
|
||
|
||
class Message(TypedDict): | ||
"""OpenAI Message object containing a role and the message content""" | ||
|
||
role: str | ||
content: str | ||
|
||
|
||
@dataclass | ||
class ModelInfo: | ||
"""Struct for model information. | ||
Would be lovely to eventually get this directly from APIs, but needs to be scraped from | ||
websites for now. | ||
""" | ||
|
||
name: str | ||
prompt_token_cost: float | ||
completion_token_cost: float | ||
max_tokens: int | ||
|
||
|
||
@dataclass | ||
class ChatModelInfo(ModelInfo): | ||
"""Struct for chat model information.""" | ||
|
||
pass | ||
|
||
|
||
@dataclass | ||
class EmbeddingModelInfo(ModelInfo): | ||
"""Struct for embedding model information.""" | ||
|
||
embedding_dimensions: int | ||
|
||
|
||
@dataclass | ||
class LLMResponse: | ||
"""Standard response struct for a response from an LLM model.""" | ||
|
||
model_info: ModelInfo | ||
prompt_tokens_used: int = 0 | ||
completion_tokens_used: int = 0 | ||
|
||
|
||
@dataclass | ||
class EmbeddingModelResponse(LLMResponse): | ||
"""Standard response struct for a response from an embedding model.""" | ||
|
||
embedding: List[float] = field(default_factory=list) | ||
|
||
def __post_init__(self): | ||
if self.completion_tokens_used: | ||
raise ValueError("Embeddings should not have completion tokens used.") | ||
|
||
|
||
@dataclass | ||
class ChatModelResponse(LLMResponse): | ||
"""Standard response struct for a response from an LLM model.""" | ||
|
||
content: str = 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
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
Empty file.
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 @@ | ||
from autogpt.llm.base import ChatModelInfo, EmbeddingModelInfo | ||
|
||
OPEN_AI_CHAT_MODELS = { | ||
"gpt-3.5-turbo": ChatModelInfo( | ||
name="gpt-3.5-turbo", | ||
prompt_token_cost=0.002, | ||
completion_token_cost=0.002, | ||
max_tokens=4096, | ||
), | ||
"gpt-4": ChatModelInfo( | ||
name="gpt-4", | ||
prompt_token_cost=0.03, | ||
completion_token_cost=0.06, | ||
max_tokens=8192, | ||
), | ||
"gpt-4-32k": ChatModelInfo( | ||
name="gpt-4-32k", | ||
prompt_token_cost=0.06, | ||
completion_token_cost=0.12, | ||
max_tokens=32768, | ||
), | ||
} | ||
|
||
OPEN_AI_EMBEDDING_MODELS = { | ||
"text-embedding-ada-002": EmbeddingModelInfo( | ||
name="text-embedding-ada-002", | ||
prompt_token_cost=0.0004, | ||
completion_token_cost=0.0, | ||
max_tokens=8191, | ||
embedding_dimensions=1536, | ||
), | ||
} | ||
|
||
OPEN_AI_MODELS = { | ||
**OPEN_AI_CHAT_MODELS, | ||
**OPEN_AI_EMBEDDING_MODELS, | ||
} |
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 was deleted.
Oops, something went wrong.