Skip to content

Commit

Permalink
Format Python code with psf/black push
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions authored and github-actions committed Feb 27, 2023
1 parent 8ecc828 commit 33df478
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions models/index_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ async def set_file_index(
return

# Send indexing message
response = await ctx.respond(embed=EmbedStatics.build_index_progress_embed())
response = await ctx.respond(
embed=EmbedStatics.build_index_progress_embed()
)

async with aiofiles.tempfile.TemporaryDirectory() as temp_path:
async with aiofiles.tempfile.NamedTemporaryFile(
Expand All @@ -383,16 +385,22 @@ async def set_file_index(
)

try:
price = await self.usage_service.get_price(embedding_model.last_token_usage, embeddings=True)
price = await self.usage_service.get_price(
embedding_model.last_token_usage, embeddings=True
)
except:
traceback.print_exc()
price = "Unknown"

file_name = file.filename
self.index_storage[ctx.user.id].add_index(index, ctx.user.id, file_name)
await response.edit(embed=EmbedStatics.get_index_set_success_embed(str(price)))
await response.edit(
embed=EmbedStatics.get_index_set_success_embed(str(price))
)
except Exception as e:
await ctx.channel.send(embed=EmbedStatics.get_index_set_failure_embed(str(e)))
await ctx.channel.send(
embed=EmbedStatics.get_index_set_failure_embed(str(e))
)
traceback.print_exc()

async def set_link_index(
Expand All @@ -405,7 +413,6 @@ async def set_link_index(

response = await ctx.respond(embed=EmbedStatics.build_index_progress_embed())
try:

embedding_model = OpenAIEmbedding()

# Pre-emptively connect and get the content-type of the response
Expand Down Expand Up @@ -448,7 +455,9 @@ async def set_link_index(
)

try:
price = await self.usage_service.get_price(embedding_model.last_token_usage, embeddings=True)
price = await self.usage_service.get_price(
embedding_model.last_token_usage, embeddings=True
)
except:
traceback.print_exc()
price = "Unknown"
Expand Down Expand Up @@ -715,7 +724,9 @@ async def query(
else:
os.environ["OPENAI_API_KEY"] = user_api_key

ctx_response = await ctx.respond(embed=EmbedStatics.build_index_query_progress_embed(query))
ctx_response = await ctx.respond(
embed=EmbedStatics.build_index_query_progress_embed(query)
)

try:
llm_predictor = LLMPredictor(llm=OpenAI(model_name="text-davinci-003"))
Expand All @@ -742,7 +753,13 @@ async def query(
)

try:
total_price = round(await self.usage_service.get_price(llm_predictor.last_token_usage) + await self.usage_service.get_price(embedding_model.last_token_usage, True), 6)
total_price = round(
await self.usage_service.get_price(llm_predictor.last_token_usage)
+ await self.usage_service.get_price(
embedding_model.last_token_usage, True
),
6,
)
except:
total_price = "Unknown"

Expand All @@ -756,7 +773,9 @@ async def query(
timeout=None,
author_check=False,
)
await ctx_response.edit(embed=EmbedStatics.build_index_query_success_embed(query,total_price))
await ctx_response.edit(
embed=EmbedStatics.build_index_query_success_embed(query, total_price)
)
await paginator.respond(ctx.interaction)
except Exception:
traceback.print_exc()
Expand Down

0 comments on commit 33df478

Please sign in to comment.