Skip to content

Commit

Permalink
update requirements + use gpt-4 and add support for new endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
agardnerIT committed Jun 11, 2024
1 parent a95c97b commit 2608961
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
19 changes: 13 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
WEAVIATE_STARTUP_PERIOD_SECONDS = 30
COMPLETION_LENGTH = os.environ.get("COMPLETION_LENGTH", 20)
CACHE_MINUTES = os.environ.get("CACHE_MINUTES", 60)
AI_MODEL = os.environ.get("AI_MODEL", "gpt-3.5-turbo")
AI_MODEL = os.environ.get("AI_MODEL", "gpt-4")
AI_SYSTEM = "openai"
MAX_PROMPT_LENGTH = 50
AI_EMBEDDING_MODEL = "text-embedding-ada-002"
AI_EMBEDDING_MODEL = os.environ.get("AI_EMBEDDING_MODEL", "text-embedding-ada-002")
OPENAI_BASE_URL = os.environ.get("OPENAI_BASE_URL", "")

Traceloop.init()
Traceloop.init(app_name="my app name")

# Temporary until LLM Semantic conventions
# are released: https:#github.com/traceloop/semantic-conventions/blob/4ee7433cd9bbda00bca0f118c1230ff13eac62e5/docs/gen-ai/llm-spans.md
Expand Down Expand Up @@ -81,7 +82,14 @@
#############
# CONFIGURE

openai_client = OpenAI(api_key=OPENAI_KEY )
if OPENAI_BASE_URL != "":
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {OPENAI_KEY}"
}
openai_client = OpenAI(base_url=OPENAI_BASE_URL, default_headers=headers)
else:
openai_client = OpenAI(api_key=OPENAI_KEY)

############
# CONFIGURE ENDPOINTS
Expand All @@ -92,7 +100,6 @@
@app.get("/api/v1/completion")
def submit_completion(prompt: str):
with otel_tracer.start_as_current_span(name="/api/v1/completion") as current_span:
# with otel_tracer.start_as_current_span(name="/api/v1/completion", attributes={ SEMCONV_TMP_GENAI_SYSTEM: AI_SYSTEM, SEMCONV_TMP_GENAI_REQUEST_MODEL: AI_MODEL, SEMCONV_TMP_GENAI_USAGE_COMPLETION_TOKENS: COMPLETION_LENGTH, SEMCONV_GENAI_REQUEST_PROMPT: prompt }) as current_span:
logger.info(f"Input prompt was: {prompt}")
cache_hit = False

Expand Down Expand Up @@ -219,7 +226,7 @@ def get_embedding_vector(text):
# current_span.set_attribute(key="model", value=AI_EMBEDDING_MODEL)
# current_span.set_attribute(key="input", value=text)

resp = openai_client.embeddings.create(input=text, model=AI_EMBEDDING_MODEL)
resp = openai_client.embeddings.create(input=text, model=AI_EMBEDDING_MODEL, encoding_format="float")

return resp.data[0].embedding

Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openai == 1.26.0
fastapi == 0.111.0
uvicorn == 0.29.0
weaviate-client == 3.26.2
opentelemetry-api == 1.24.0
opentelemetry-sdk == 1.24.0
opentelemetry-exporter-otlp-proto-grpc == 1.24.0
traceloop-sdk == 0.18.0
opentelemetry-api == 1.25.0
opentelemetry-sdk == 1.25.0
opentelemetry-exporter-otlp-proto-grpc == 1.25.0
traceloop-sdk == 0.22.0

0 comments on commit 2608961

Please sign in to comment.