-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathconst.py
More file actions
98 lines (75 loc) · 2.55 KB
/
const.py
File metadata and controls
98 lines (75 loc) · 2.55 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- coding: utf-8 -*-
# pylint: disable=E1101
"""A module containing constants for the OpenAI API."""
import logging
import os
from pathlib import Path
import hcl2
import openai
MODULE_NAME = "openai_api"
HERE = os.path.abspath(os.path.dirname(__file__))
PROJECT_ROOT = str(Path(HERE).parent)
PYTHON_ROOT = str(Path(PROJECT_ROOT).parent)
TERRAFORM_ROOT = str(Path(PROJECT_ROOT).parent.parent)
REPO_ROOT = str(Path(TERRAFORM_ROOT).parent.parent)
TERRAFORM_TFVARS = os.path.join(TERRAFORM_ROOT, "terraform.tfvars")
if not os.path.exists(TERRAFORM_TFVARS):
TERRAFORM_TFVARS = os.path.join(PROJECT_ROOT, "terraform.tfvars")
TFVARS = {}
IS_USING_TFVARS = False
logger = logging.getLogger(__name__)
try:
with open(TERRAFORM_TFVARS, "r", encoding="utf-8") as f:
TFVARS = hcl2.load(f)
IS_USING_TFVARS = True
except FileNotFoundError:
logger.debug("No terraform.tfvars file found. Using default values.")
# pylint: disable=too-few-public-methods
class OpenAIResponseCodes:
"""Http response codes from openai API"""
HTTP_RESPONSE_OK = 200
HTTP_RESPONSE_BAD_REQUEST = 400
HTTP_RESPONSE_INTERNAL_SERVER_ERROR = 500
class OpenAIObjectTypes:
"""V1 API Object Types (replace OpeanAIEndPoint)"""
Embedding = "embedding"
ChatCompletion = "chat.completion"
Moderation = "moderation"
Image = "image"
Audio = "audio"
Models = "models"
all_object_types = [Embedding, ChatCompletion, Moderation, Image, Audio, Models]
class OpenAIEndPoint:
"""
A class representing an endpoint for the OpenAI API.
Attributes:
api_key (str): The API key to use for authentication.
endpoint (str): The URL of the OpenAI API endpoint.
"""
Embedding = "Embedding"
ChatCompletion = "chat/completions"
Moderation = "Moderation"
Image = "Image"
Audio = "Audio"
Models = "Model"
all_endpoints = [Embedding, ChatCompletion, Moderation, Image, Audio, Models]
# pylint: disable=too-few-public-methods
class OpenAIMessageKeys:
"""A class representing the keys for a message in the OpenAI API."""
OPENAI_USER_MESSAGE_KEY = "user"
OPENAI_ASSISTANT_MESSAGE_KEY = "assistant"
OPENAI_SYSTEM_MESSAGE_KEY = "system"
OPENAI_TOOL_KEY = "tool"
all = [
OPENAI_SYSTEM_MESSAGE_KEY,
OPENAI_USER_MESSAGE_KEY,
OPENAI_ASSISTANT_MESSAGE_KEY,
OPENAI_TOOL_KEY,
]
VALID_EMBEDDING_MODELS = [
"text-embedding-ada-002",
"text-similarity-*-001",
"text-search-*-*-001",
"code-search-*-*-001",
]
LANGCHAIN_MESSAGE_HISTORY_ROLES = ["user", "assistant"]