Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RAG #206

Merged
merged 35 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cffa117
feat: add http_server_extension
wangyoucao577 Aug 7, 2024
620679e
feat: add aliyun_text_embedding
wangyoucao577 Aug 7, 2024
4a3f275
feat: add aliyun_analyticdb_vector_storage
wangyoucao577 Aug 7, 2024
4a88988
feat: add file_chunker
wangyoucao577 Aug 7, 2024
7557830
feat: file chunking
wangyoucao577 Aug 7, 2024
8f5183e
feat: create collection by file_chunker
wangyoucao577 Aug 7, 2024
447806c
fix: typo
wangyoucao577 Aug 7, 2024
68e65d0
feat: add call_chat api
wangyoucao577 Aug 8, 2024
a90761e
feat: basic chat engine
wangyoucao577 Aug 8, 2024
f18205a
feat: rag querying
wangyoucao577 Aug 8, 2024
04d1a3f
feat: add qwen.rag graph
wangyoucao577 Aug 8, 2024
34ccc29
fix: cozy tts drain and interrupt
wangyoucao577 Aug 8, 2024
bd29cfa
chore(): add api upload
sunshinexcode Aug 9, 2024
f175b8c
chore(): add api for /vector/document (#193)
sunshinexcode Aug 12, 2024
18d967c
feat: update querying collection
wangyoucao577 Aug 12, 2024
da165ee
fix(): fix graphNameMap not being able to retrieve environment variab…
sunshinexcode Aug 12, 2024
b1b77e0
upgrade image version (#197)
sunshinexcode Aug 13, 2024
51b73ed
feat: web ui update (#198)
QinZhen001 Aug 13, 2024
09d4b6a
feat: update agora_rtc
wangyoucao577 Aug 14, 2024
8d428b2
fix: audio stuck, calculate ttfb
wangyoucao577 Aug 14, 2024
ff31405
fix: too slow output
wangyoucao577 Aug 14, 2024
4230475
feat: fix text glitches
plutoless Aug 14, 2024
de5d79c
feat: support graph selection
plutoless Aug 14, 2024
69960ca
fix(): collection must start with a letter (#205)
sunshinexcode Aug 14, 2024
f78c764
feat: calculate latency
wangyoucao577 Aug 14, 2024
cbfac58
fix: cozy tts too slow
wangyoucao577 Aug 14, 2024
4fc6e21
feat: improve prompt
wangyoucao577 Aug 14, 2024
fd592e5
feat: add api
wangyoucao577 Aug 14, 2024
3b7fc6a
fix: tmp move litellm to bak
plutoless Aug 14, 2024
eacd25e
feat: interrput
wangyoucao577 Aug 14, 2024
34e8c68
feat: pdf selection optimization
plutoless Aug 14, 2024
591b179
feat: replace cosy with azure
plutoless Aug 14, 2024
6586a3f
fix: fix pdf select
plutoless Aug 14, 2024
a7f73ef
feat: add playground prebuilt image
plutoless Aug 14, 2024
0d118a0
Merge remote-tracking branch 'origin/main' into feature/rag
wangyoucao577 Aug 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
"name": "astra",
"image": "ghcr.io/rte-design/astra_agents_build:0.3.5",
"image": "ghcr.io/rte-design/astra_agents_build:0.3.6",
"customizations": {
"vscode": {
"extensions": [
Expand Down
18 changes: 17 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
# ------------------------------

# Log path
LOG_PATH=/tmp
LOG_PATH=/tmp/astra
# Graph designer server port
GRAPH_DESIGNER_SERVER_PORT=49483
# The corresponding graph name based on the language
GRAPH_NAME_ZH=va.openai.azure
GRAPH_NAME_EN=va.openai.azure
# Server port
SERVER_PORT=8080
# Maximum number of workers
Expand All @@ -26,6 +29,19 @@ AGORA_APP_CERTIFICATE=
# Worker Configuration
# ------------------------------

# Extension: aliyun_analyticdb_vector_storage
ALIBABA_CLOUD_ACCESS_KEY_ID=
ALIBABA_CLOUD_ACCESS_KEY_SECRET=
ALIYUN_ANALYTICDB_ACCOUNT=
ALIYUN_ANALYTICDB_ACCOUNT_PASSWORD=
ALIYUN_ANALYTICDB_INSTANCE_ID=
ALIYUN_ANALYTICDB_INSTANCE_REGION=cn-shanghai
ALIYUN_ANALYTICDB_NAMESPACE=
ALIYUN_ANALYTICDB_NAMESPACE_PASSWORD=

# Extension: aliyun_text_embedding
ALIYUN_TEXT_EMBEDDING_API_KEY=

# Extension: bedrock_llm
# Extension: polly_tts
AWS_ACCESS_KEY_ID=
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/rte-design/astra_agents_build:0.3.5 AS builder
FROM ghcr.io/rte-design/astra_agents_build:0.3.6 AS builder

ARG SESSION_CONTROL_CONF=session_control.conf

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import vector_storage_addon
from .log import logger

logger.info("aliyun_analyticdb_vector_storage extension loaded")
98 changes: 98 additions & 0 deletions agents/addon/extension/aliyun_analyticdb_vector_storage/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-

try:
from .log import logger
except ImportError:
from log import logger
import asyncio
import threading
from typing import Coroutine
from concurrent.futures import Future


from alibabacloud_gpdb20160503.client import Client as gpdb20160503Client
from alibabacloud_tea_openapi import models as open_api_models


# maybe need multiple clients
class AliGPDBClient:
def __init__(self, access_key_id, access_key_secret, endpoint):
self.stopEvent = asyncio.Event()
self.loop = None
self.tasks = asyncio.Queue()
self.access_key_id = access_key_id
self.access_key_secret = access_key_secret
self.endpoint = endpoint
self.client = self.create_client()
self.thread = threading.Thread(
target=asyncio.run, args=(self.__thread_routine(),)
)
self.thread.start()

async def stop_thread(self):
self.stopEvent.set()

def create_client(self) -> gpdb20160503Client:
config = open_api_models.Config(
access_key_id=self.access_key_id,
access_key_secret=self.access_key_secret,
endpoint=self.endpoint,
)
return gpdb20160503Client(config)

def get(self) -> gpdb20160503Client:
return self.client

def close(self):
if (self.loop is not None) and self.thread.is_alive():
self.stopEvent.set()
asyncio.run_coroutine_threadsafe(self.stop_thread(), self.loop)
self.thread.join()

async def __thread_routine(self):
logger.info("client __thread_routine start")
self.loop = asyncio.get_running_loop()
tasks = set()
while not self.stopEvent.is_set():
if not self.tasks.empty():
coro, future = await self.tasks.get()
try:
task = asyncio.create_task(coro)
tasks.add(task)
task.add_done_callback(lambda t: future.set_result(t.result()))
except Exception as e:
future.set_exception(e)
elif tasks:
done, tasks = await asyncio.wait(
tasks, return_when=asyncio.FIRST_COMPLETED
)
for task in done:
if task.exception():
logger.error(f"task exception: {task.exception()}")
future.set_exception(task.exception())
else:
await asyncio.sleep(0.1)
logger.info("client __thread_routine end")

async def submit_task(self, coro: Coroutine) -> Future:
future = Future()
await self.tasks.put((coro, future))
return future

def submit_task_with_new_thread(self, coro: Coroutine) -> Future:
future = Future()

def run_coro_in_new_thread():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
result = loop.run_until_complete(coro)
future.set_result(result)
except Exception as e:
future.set_exception(e)
finally:
loop.close()

thread = threading.Thread(target=run_coro_in_new_thread)
thread.start()
return future
13 changes: 13 additions & 0 deletions agents/addon/extension/aliyun_analyticdb_vector_storage/log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import logging

logger = logging.getLogger("aliyun_analyticdb_vector_storage")
logger.setLevel(logging.INFO)

formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(process)d - [%(filename)s:%(lineno)d] - %(message)s"
)

console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)

logger.addHandler(console_handler)
122 changes: 122 additions & 0 deletions agents/addon/extension/aliyun_analyticdb_vector_storage/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"type": "extension",
"name": "aliyun_analyticdb_vector_storage",
"version": "0.4.0",
"language": "python",
"dependencies": [
{
"type": "system",
"name": "rte_runtime_python",
"version": "0.4"
}
],
"api": {
"property": {
"alibaba_cloud_access_key_id": {
"type": "string"
},
"alibaba_cloud_access_key_secret": {
"type": "string"
},
"adbpg_instance_id": {
"type": "string"
},
"adbpg_instance_region": {
"type": "string"
},
"adbpg_account": {
"type": "string"
},
"adbpg_account_password": {
"type": "string"
},
"adbpg_namespace": {
"type": "string"
},
"adbpg_namespace_password": {
"type": "string"
}
},
"cmd_in": [
{
"name": "upsert_vector",
"property": {
"collection_name": {
"type": "string"
},
"file_name": {
"type": "string"
},
"content": {
"type": "string"
}
}
},
{
"name": "query_vector",
"property": {
"collection_name": {
"type": "string"
},
"top_k": {
"type": "int64"
},
"embedding": {
"type": "array",
"items": {
"type": "float64"
}
}
},
"required": [
"collection_name",
"top_k",
"embedding"
],
"result": {
"property": {
"response": {
"type": "array",
"items": {
"type": "object",
"properties": {
"content": {
"type": "string"
},
"score": {
"type": "float64"
}
}
}
}
}
}
},
{
"name": "create_collection",
"property": {
"collection_name": {
"type": "string"
},
"dimension": {
"type": "int32"
}
},
"required": [
"collection_name"
]
},
{
"name": "delete_collection",
"property": {
"collection_name": {
"type": "string"
}
},
"required": [
"collection_name"
]
}
]
}
}
Loading