meilisearch async client
This commit is contained in:
parent
861a873f7e
commit
d2afe5ff25
9 changed files with 65 additions and 61 deletions
45
continuedev/poetry.lock
generated
45
continuedev/poetry.lock
generated
|
|
@ -1,5 +1,16 @@
|
|||
# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand.
|
||||
|
||||
[[package]]
|
||||
name = "aiofiles"
|
||||
version = "23.1.0"
|
||||
description = "File support for asyncio."
|
||||
optional = false
|
||||
python-versions = ">=3.7,<4.0"
|
||||
files = [
|
||||
{file = "aiofiles-23.1.0-py3-none-any.whl", hash = "sha256:9312414ae06472eb6f1d163f555e466a23aed1c8f60c30cccf7121dba2e53eb2"},
|
||||
{file = "aiofiles-23.1.0.tar.gz", hash = "sha256:edd247df9a19e0db16534d4baaf536d6609a43e1de5401d7a4c1c148753a1635"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aiohttp"
|
||||
version = "3.8.4"
|
||||
|
|
@ -223,9 +234,6 @@ files = [
|
|||
{file = "camel_converter-3.0.2.tar.gz", hash = "sha256:3b3d076e824ae979b271b4d497c90514c2b218811f76b0c368fb69da2556fe07"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
pydantic = {version = ">=1.8.2", optional = true, markers = "extra == \"pydantic\""}
|
||||
|
||||
[package.extras]
|
||||
pydantic = ["pydantic (>=1.8.2)"]
|
||||
|
||||
|
|
@ -660,16 +668,6 @@ files = [
|
|||
{file = "frozenlist-1.3.3.tar.gz", hash = "sha256:58bcc55721e8a90b88332d6cd441261ebb22342e238296bb330968952fbb3a6a"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "func-timeout"
|
||||
version = "4.3.5"
|
||||
description = "Python module which allows you to specify timeouts when calling any existing function. Also provides support for stoppable-threads"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "func_timeout-4.3.5.tar.gz", hash = "sha256:74cd3c428ec94f4edfba81f9b2f14904846d5ffccc27c92433b8b5939b5575dd"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gpt-index"
|
||||
version = "0.6.8"
|
||||
|
|
@ -951,19 +949,22 @@ files = [
|
|||
marshmallow = ">=2.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "meilisearch"
|
||||
version = "0.28.1"
|
||||
description = "The python client for Meilisearch API."
|
||||
name = "meilisearch-python-async"
|
||||
version = "1.4.8"
|
||||
description = "A Python async client for the Meilisearch API"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
python-versions = ">=3.8,<4.0"
|
||||
files = [
|
||||
{file = "meilisearch-0.28.1-py3-none-any.whl", hash = "sha256:b4cfaf140fc323c429a4e174b801bcc6dddef88bf901560ebf2fc5c0014099b5"},
|
||||
{file = "meilisearch-0.28.1.tar.gz", hash = "sha256:4e8627abe1394f04125c99e60f9f4356ba200effe5735ce9b8a44b09e3c6403c"},
|
||||
{file = "meilisearch_python_async-1.4.8-py3-none-any.whl", hash = "sha256:dea8da89ea254cd2de7e3c0f0883e98486fc724ba8212e4fe19b2b44d9ca6aa1"},
|
||||
{file = "meilisearch_python_async-1.4.8.tar.gz", hash = "sha256:ebcea0ed800dce291809ec599384f103da55362b4485997ff4daa0010c935fc6"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
camel-converter = {version = "*", extras = ["pydantic"]}
|
||||
requests = "*"
|
||||
aiofiles = ">=0.7"
|
||||
camel-converter = ">=1.0.0"
|
||||
httpx = ">=0.17"
|
||||
pydantic = ">=1.8"
|
||||
PyJWT = ">=2.3.0"
|
||||
|
||||
[[package]]
|
||||
name = "monotonic"
|
||||
|
|
@ -2311,4 +2312,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.8.1"
|
||||
content-hash = "53ad0b6fa45f00fe53fbd2a90845ae1647e0be22b0b52dfe55996f2c9a6faa38"
|
||||
content-hash = "126119ec6b94f1da4af9f8f2de4352df20522652cd58726546bd2fb46b40a9ef"
|
||||
|
|
|
|||
|
|
@ -27,9 +27,8 @@ directory-tree = "^0.0.3.1"
|
|||
anthropic = "^0.3.4"
|
||||
chevron = "^0.14.0"
|
||||
psutil = "^5.9.5"
|
||||
meilisearch = "^0.28.1"
|
||||
pygithub = "^1.59.0"
|
||||
func-timeout = "^4.3.5"
|
||||
meilisearch-python-async = "^1.4.8"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
typegen = "src.continuedev.models.generate_json_schema:main"
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class Autopilot(ContinueBaseModel):
|
|||
autopilot.continue_sdk = await ContinueSDK.create(autopilot)
|
||||
|
||||
# Load documents into the search index
|
||||
autopilot.context_manager = ContextManager(
|
||||
autopilot.context_manager = await ContextManager.create(
|
||||
autopilot.continue_sdk.config.context_providers + [
|
||||
HighlightedCodeContextProvider(ide=ide),
|
||||
FileContextProvider(workspace_dir=ide.workspace_directory)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
from abc import abstractmethod
|
||||
from typing import Dict, List
|
||||
import meilisearch
|
||||
from meilisearch_python_async import Client
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
|
|
@ -50,21 +50,21 @@ class ContextProvider(BaseModel):
|
|||
"""
|
||||
return [ChatMessage(role="user", content=f"{item.description.name}: {item.description.description}\n\n{item.content}", summary=item.description.description) for item in await self.get_selected_items()]
|
||||
|
||||
async def get_item(self, id: ContextItemId, query: str, search_client: meilisearch.Client) -> ContextItem:
|
||||
async def get_item(self, id: ContextItemId, query: str, search_client: Client) -> ContextItem:
|
||||
"""
|
||||
Returns the ContextItem with the given id.
|
||||
|
||||
Default implementation uses the search index to get the item.
|
||||
"""
|
||||
result = search_client.index(
|
||||
result = await search_client.index(
|
||||
SEARCH_INDEX_NAME).get_document(id.to_string())
|
||||
return ContextItem(
|
||||
description=ContextItemDescription(
|
||||
name=result.name,
|
||||
description=result.description,
|
||||
name=result["name"],
|
||||
description=result["description"],
|
||||
id=id
|
||||
),
|
||||
content=result.content
|
||||
content=result["content"]
|
||||
)
|
||||
|
||||
async def delete_context_with_ids(self, ids: List[ContextItemId]):
|
||||
|
|
@ -85,7 +85,7 @@ class ContextProvider(BaseModel):
|
|||
"""
|
||||
self.selected_items = []
|
||||
|
||||
async def add_context_item(self, id: ContextItemId, query: str, search_client: meilisearch.Client):
|
||||
async def add_context_item(self, id: ContextItemId, query: str, search_client: Client):
|
||||
"""
|
||||
Adds the given ContextItem to the list of ContextItems.
|
||||
|
||||
|
|
@ -126,21 +126,26 @@ class ContextManager:
|
|||
"""
|
||||
return sum([await provider.get_chat_messages() for provider in self.context_providers.values()], [])
|
||||
|
||||
search_client: meilisearch.Client
|
||||
|
||||
def __init__(self, context_providers: List[ContextProvider]):
|
||||
self.search_client = meilisearch.Client('http://localhost:7700')
|
||||
|
||||
# If meilisearch isn't running, don't use any ContextProviders that might depend on it
|
||||
if not check_meilisearch_running():
|
||||
context_providers = list(
|
||||
filter(lambda cp: cp.title == "code", context_providers))
|
||||
search_client: Client
|
||||
|
||||
def __init__(self, context_providers: List[ContextProvider], search_client: Client):
|
||||
self.search_client = search_client
|
||||
self.context_providers = {
|
||||
prov.title: prov for prov in context_providers}
|
||||
self.provider_titles = {
|
||||
provider.title for provider in context_providers}
|
||||
|
||||
@classmethod
|
||||
async def create(cls, context_providers: List[ContextProvider]):
|
||||
search_client = Client('http://localhost:7700')
|
||||
health = await search_client.health()
|
||||
if not health.status == "available":
|
||||
print("MeiliSearch not running, avoiding any dependent context providers")
|
||||
context_providers = list(
|
||||
filter(lambda cp: cp.title == "code", context_providers))
|
||||
|
||||
return cls(context_providers, search_client)
|
||||
|
||||
async def load_index(self):
|
||||
for _, provider in self.context_providers.items():
|
||||
context_items = await provider.provide_context_items()
|
||||
|
|
@ -154,8 +159,7 @@ class ContextManager:
|
|||
for item in context_items
|
||||
]
|
||||
if len(documents) > 0:
|
||||
self.search_client.index(
|
||||
SEARCH_INDEX_NAME).add_documents(documents)
|
||||
await self.search_client.index(SEARCH_INDEX_NAME).add_documents(documents)
|
||||
|
||||
# def compile_chat_messages(self, max_tokens: int) -> List[Dict]:
|
||||
# """
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import os
|
||||
from typing import Any, Dict, List
|
||||
|
||||
import meilisearch
|
||||
from meilisearch_python_async import Client
|
||||
from ...core.main import ChatMessage
|
||||
from ...models.filesystem import RangeInFile, RangeInFileWithContents
|
||||
from ...core.context import ContextItem, ContextItemDescription, ContextItemId
|
||||
|
|
@ -187,5 +187,5 @@ class HighlightedCodeContextProvider(BaseModel):
|
|||
for hr in self.highlighted_ranges:
|
||||
hr.item.editing = hr.item.description.id.to_string() in ids
|
||||
|
||||
async def add_context_item(self, id: ContextItemId, query: str, search_client: meilisearch.Client, prev: List[ContextItem] = None) -> List[ContextItem]:
|
||||
async def add_context_item(self, id: ContextItemId, query: str, search_client: Client, prev: List[ContextItem] = None) -> List[ContextItem]:
|
||||
raise NotImplementedError()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import asyncio
|
||||
import subprocess
|
||||
import time
|
||||
import meilisearch
|
||||
from meilisearch_python_async import Client
|
||||
import psutil
|
||||
import os
|
||||
from fastapi import FastAPI
|
||||
|
|
@ -87,13 +86,14 @@ if __name__ == "__main__":
|
|||
# cpu_thread = threading.Thread(target=cpu_usage_loop)
|
||||
# cpu_thread.start()
|
||||
|
||||
try:
|
||||
start_meilisearch()
|
||||
except Exception as e:
|
||||
print("Failed to start MeiliSearch")
|
||||
print(e)
|
||||
# try:
|
||||
# await start_meilisearch()
|
||||
# except Exception as e:
|
||||
# print("Failed to start MeiliSearch")
|
||||
# print(e)
|
||||
|
||||
run_server()
|
||||
except Exception as e:
|
||||
print("Error starting Continue server: ", e)
|
||||
cleanup()
|
||||
raise e
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import os
|
|||
import shutil
|
||||
import subprocess
|
||||
|
||||
import meilisearch
|
||||
from meilisearch_python_async import Client
|
||||
from ..libs.util.paths import getServerFolderPath
|
||||
|
||||
|
||||
|
|
@ -41,14 +41,14 @@ def ensure_meilisearch_installed():
|
|||
f"curl -L https://install.meilisearch.com | sh", shell=True, check=True, cwd=serverPath)
|
||||
|
||||
|
||||
def check_meilisearch_running() -> bool:
|
||||
async def check_meilisearch_running() -> bool:
|
||||
"""
|
||||
Checks if MeiliSearch is running.
|
||||
"""
|
||||
|
||||
try:
|
||||
client = meilisearch.Client('http://localhost:7700')
|
||||
resp = client.health()
|
||||
client = Client('http://localhost:7700')
|
||||
resp = await client.health()
|
||||
if resp["status"] != "available":
|
||||
return False
|
||||
return True
|
||||
|
|
@ -56,7 +56,7 @@ def check_meilisearch_running() -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def start_meilisearch():
|
||||
async def start_meilisearch():
|
||||
"""
|
||||
Starts the MeiliSearch server, wait for it.
|
||||
"""
|
||||
|
|
@ -71,7 +71,7 @@ def start_meilisearch():
|
|||
ensure_meilisearch_installed()
|
||||
|
||||
# Check if MeiliSearch is running
|
||||
if not check_meilisearch_running():
|
||||
if not await check_meilisearch_running():
|
||||
print("Starting MeiliSearch...")
|
||||
subprocess.Popen(["./meilisearch"], cwd=serverPath, stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.STDOUT, close_fds=True, start_new_session=True)
|
||||
|
|
|
|||
4
extension/package-lock.json
generated
4
extension/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "0.0.195",
|
||||
"version": "0.0.199",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "0.0.195",
|
||||
"version": "0.0.199",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
"displayName": "Continue",
|
||||
"pricing": "Free",
|
||||
"description": "The open-source coding autopilot",
|
||||
"version": "0.0.195",
|
||||
"version": "0.0.199",
|
||||
"publisher": "Continue",
|
||||
"engines": {
|
||||
"vscode": "^1.67.0"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue