forked from AlmogBaku/llm-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocol.py
66 lines (50 loc) · 1.92 KB
/
protocol.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from typing import Literal, Optional, List, Union
from openai.types.chat import ChatCompletionMessageParam
from pydantic import BaseModel, Field
from pydantic_settings import BaseSettings, SettingsConfigDict
class Model(BaseModel):
name: str
description: str = ""
type: Literal['chat', 'completions']
system_prompt: Optional[bool] = None
max_tokens: Optional[int] = None
vendor: Optional[str] = None
api_key: Optional[str] = Field(None, hidden=True)
base_url: Optional[str] = Field(None, hidden=True)
class ModelsConfig(BaseModel):
urls: Optional[List[str]] = None
oai_urls: Optional[List[str]] = None
models: Optional[List[Model]] = None
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8', yaml_file='settings.yaml')
openai_api_key: Optional[str] = None
openai_organization: Optional[str] = None
openai_base_url: Optional[str] = None
models: ModelsConfig = ModelsConfig()
dist_dir: Optional[str] = None
class ChatCompletionsRequest(BaseModel):
model: str
messages: List[ChatCompletionMessageParam]
max_tokens: Optional[int] = None
temperature: Optional[float] = None
top_p: Optional[float] = None
stop: Optional[Union[List[str], str]] = None
stream: Literal[True] = True
def __init__(self, **data) -> None:
if 'stop' in data and not data['stop']:
data['stop'] = None
data['stream'] = True
super().__init__(**data)
class CompletionsRequest(BaseModel):
model: str
prompt: str
max_tokens: Optional[int] = None
temperature: Optional[float] = None
top_p: Optional[float] = None
stop: Optional[Union[List[str], str]] = None
stream: Literal[True] = True
def __init__(self, **data) -> None:
if 'stop' in data and not data['stop']:
data['stop'] = None
data['stream'] = True
super().__init__(**data)