Kaveen Kumarasinghe 1 year ago
commit aa13c2c5e6

@ -684,7 +684,9 @@ class Commands(discord.Cog, name="Commands"):
@add_to_group("index") @add_to_group("index")
@discord.slash_command( @discord.slash_command(
name="recurse-link", description="Recursively index a link", guild_ids=ALLOWED_GUILDS name="recurse-link",
description="Recursively index a link",
guild_ids=ALLOWED_GUILDS,
) )
@discord.guild_only() @discord.guild_only()
@discord.option( @discord.option(

@ -121,7 +121,7 @@ class IndexService(discord.Cog, name="IndexService"):
) )
async def set_index_link_recurse_command( async def set_index_link_recurse_command(
self, ctx, link: str = None, depth:int = 1 self, ctx, link: str = None, depth: int = 1
): ):
await ctx.defer() await ctx.defer()
"""Command handler to set a file as your personal index""" """Command handler to set a file as your personal index"""
@ -129,7 +129,6 @@ class IndexService(discord.Cog, name="IndexService"):
await ctx.respond("Please provide a link") await ctx.respond("Please provide a link")
return return
user_api_key = None user_api_key = None
if USER_INPUT_API_KEYS: if USER_INPUT_API_KEYS:
user_api_key = await TextService.get_user_api_key( user_api_key = await TextService.get_user_api_key(

@ -40,7 +40,8 @@ from llama_index import (
IndexStructType, IndexStructType,
OpenAIEmbedding, OpenAIEmbedding,
GithubRepositoryReader, GithubRepositoryReader,
MockEmbedding, download_loader, MockEmbedding,
download_loader,
) )
from llama_index.readers.web import DEFAULT_WEBSITE_EXTRACTOR from llama_index.readers.web import DEFAULT_WEBSITE_EXTRACTOR
@ -399,7 +400,9 @@ class Index_handler:
suffix = value suffix = value
break break
if not suffix: if not suffix:
await ctx.send("Could not determine the file type of the attachment, attempting a dirty index..") await ctx.send(
"Could not determine the file type of the attachment, attempting a dirty index.."
)
return return
# Send indexing message # Send indexing message
@ -412,11 +415,16 @@ class Index_handler:
async with aiofiles.tempfile.NamedTemporaryFile( async with aiofiles.tempfile.NamedTemporaryFile(
suffix=suffix, dir=temp_path, delete=False suffix=suffix, dir=temp_path, delete=False
) as temp_file: ) as temp_file:
await file.save(temp_file.name) await file.save(temp_file.name)
embedding_model = OpenAIEmbedding() embedding_model = OpenAIEmbedding()
index = await self.loop.run_in_executor( index = await self.loop.run_in_executor(
None, partial(self.index_file, Path(temp_file.name), embedding_model, suffix) None,
partial(
self.index_file,
Path(temp_file.name),
embedding_model,
suffix,
),
) )
await self.usage_service.update_usage( await self.usage_service.update_usage(
embedding_model.last_token_usage, embeddings=True embedding_model.last_token_usage, embeddings=True
@ -479,7 +487,9 @@ class Index_handler:
# Check if the link contains youtube in it # Check if the link contains youtube in it
loader = RemoteDepthReader(depth=depth) loader = RemoteDepthReader(depth=depth)
documents = await self.loop.run_in_executor(None, partial(loader.load_data, [link])) documents = await self.loop.run_in_executor(
None, partial(loader.load_data, [link])
)
index = await self.loop.run_in_executor( index = await self.loop.run_in_executor(
None, None,
functools.partial( functools.partial(

Loading…
Cancel
Save