Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8395862

Browse files
committed
generated file: api/schemas/openai.py
1 parent a0f9815 commit 8395862

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

‎api/schemas/openai.py‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from pydantic import BaseModel, validator
2+
from typing import Optional, List
3+
4+
class OpenAIRequest(BaseModel):
5+
text: str
6+
model: str = "text-davinci-003"
7+
temperature: float = 0.7
8+
max_tokens: int = 256
9+
source_language: Optional[str] = None
10+
target_language: Optional[str] = None
11+
12+
@validator("model")
13+
def model_must_be_valid(cls, value):
14+
valid_models = ["text-davinci-003", "text-curie-001", "text-babbage-001", "text-ada-001"]
15+
if value not in valid_models:
16+
raise ValueError("Invalid model. Choose from: " + ", ".join(valid_models))
17+
return value
18+
19+
@validator("temperature")
20+
def temperature_must_be_valid(cls, value):
21+
if value < 0 or value > 1:
22+
raise ValueError("Temperature must be between 0 and 1")
23+
return value
24+
25+
@validator("max_tokens")
26+
def max_tokens_must_be_valid(cls, value):
27+
if value < 1 or value > 4096:
28+
raise ValueError("Max tokens must be between 1 and 4096")
29+
return value
30+
31+
class OpenAIResponse(BaseModel):
32+
response: str
33+
34+
class OpenAIChoice(BaseModel):
35+
text: str
36+
37+
class OpenAIUsage(BaseModel):
38+
prompt_tokens: int
39+
completion_tokens: int
40+
total_tokens: int
41+
42+
class OpenAIModel(BaseModel):
43+
id: str
44+
object: str
45+
created: int
46+
owned_by: str
47+
permissions: List[dict]
48+
root: str
49+
parent: Optional[str]
50+
is_moderation_model: bool
51+
is_text_search_model: bool
52+
is_translation_model: bool
53+
is_code_model: bool
54+
is_embedding_model: bool
55+
is_question_answering_model: bool
56+
is_completion_model: bool
57+
is_chat_completion_model: bool
58+
is_fine_tuned: bool
59+
is_available: bool

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /