Skip to content

Commit

Permalink
Make this better work with other models
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyannn committed Nov 29, 2023
1 parent eae08d3 commit 9e02512
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions de_wiki_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def complete(prompt):
}
],
model=OPENAI_MODEL,
max_tokens=8192,
)
.choices[0]
.message.content
Expand All @@ -135,7 +136,7 @@ def format_chunk(chunk_id):
return f"""{chunk_id} [{data[chunk_id]["title"]}] {data[chunk_id]["text"]}"""

while question:
logging.info("Answering %s", question)
logging.info("Answering '%s'", question)

ids_scores = embeddings.search(question, limit=CONTEXT_CHOICES)
for row_id, score in ids_scores:
Expand All @@ -157,8 +158,14 @@ def format_chunk(chunk_id):
logging.error("API wasn't happy: %s", e)
else:
try:
# While ChatGPT correctly returned only the ids of accepted chunks,
# other models may add text before or after the chunk id list.
accepted_id_string = next(
s for s in completion.split() if s and s[0].isdigit()
)
print("---- Accepted ----")
accepted_ids = [int(s) for s in completion.split()]

accepted_ids = [int(s) for s in accepted_id_string.split()]
for cid in accepted_ids:
print(format_chunk(cid))

Expand All @@ -177,7 +184,9 @@ def format_chunk(chunk_id):

except ValueError:
logging.warning(
"Received a response that I cannot parse: %s", completion
"Received a response to '%s' that I cannot parse: '%s'",
rescoring_prompt,
completion,
)

question = input("Question: ")
Expand Down

0 comments on commit 9e02512

Please sign in to comment.