Skip to content

Commit

Permalink
Search: use gpt-4-1106-preview model
Browse files Browse the repository at this point in the history
  • Loading branch information
YuraLukashik committed Nov 6, 2023
1 parent c3c0d69 commit ae36d77
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/semantic_search/semantic_search/external_services/openai.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import math
import re
from typing import List, Any
import openai
from retry import retry
Expand All @@ -25,14 +23,12 @@ def create_embeddings(texts: List[str]) -> List[Any]:

@retry(delay=3, backoff=2, tries=8)
def gpt_query(query: str) -> str:
max_tokens = 3300 - estimate_tokens_number(query)
completion = openai.Completion.create(model="gpt-3.5-turbo-instruct", prompt=query, max_tokens=max_tokens)
return completion.choices[0].text.strip()


def estimate_tokens_number(text: str) -> int:
words = re.findall(r'\b\w+\b', text)
return math.ceil(sum(map(lambda w: len(w) / 2, words)))
summary = openai.ChatCompletion.create(
model="gpt-4-1106-preview",
messages=[{"role": "user", "content": query}],
response_format={"type": "json_object"},
)
return summary.choices[0].message.content.strip()


@retry(delay=3, backoff=2, tries=8)
Expand Down

0 comments on commit ae36d77

Please sign in to comment.