Spaces:
Running
Running
Arjen Robben
commited on
Commit
·
a1b1b32
1
Parent(s):
5544b1c
llama index upgrade version migration and ollama chat backend
Browse files- app.py +22 -33
- chat_template.py +2 -2
- chatbot.py +1 -2
- custom_io.py +2 -2
- poetry.lock +0 -0
- pyproject.toml +32 -0
- service_provider_config.py +4 -4
app.py
CHANGED
@@ -4,27 +4,31 @@ import openai
|
|
4 |
import os
|
5 |
from dotenv import load_dotenv
|
6 |
import phoenix as px
|
|
|
7 |
import llama_index
|
8 |
-
from llama_index import
|
9 |
-
from llama_index.chat_engine.types import ChatMode
|
10 |
-
from llama_index.llms import ChatMessage, MessageRole
|
|
|
|
|
|
|
11 |
from llama_index.vector_stores.qdrant import QdrantVectorStore
|
12 |
-
|
13 |
-
from llama_index.
|
14 |
-
|
15 |
from chat_template import CHAT_TEXT_QA_PROMPT, TEXT_QA_SYSTEM_PROMPT
|
16 |
from schemas import ChatbotVersion, ServiceProvider
|
17 |
from chatbot import Chatbot, IndexBuilder
|
18 |
from custom_io import MarkdownReader, UnstructuredReader, default_file_metadata_func
|
19 |
from qdrant import client as qdrantClient
|
20 |
-
from llama_index import set_global_service_context
|
21 |
|
22 |
from service_provider_config import get_service_provider_config
|
23 |
|
24 |
load_dotenv()
|
25 |
# initial service setup
|
26 |
px.launch_app()
|
27 |
-
llama_index.set_global_handler("arize_phoenix")
|
28 |
# llama_index.set_global_handler("wandb", run_args={"project": "llamaindex"})
|
29 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
30 |
|
@@ -32,16 +36,14 @@ IS_LOAD_FROM_VECTOR_STORE = True
|
|
32 |
VDB_COLLECTION_NAME = "demo-v6"
|
33 |
MODEL_NAME = ChatbotVersion.CHATGPT_4.value
|
34 |
|
35 |
-
|
36 |
CHUNK_SIZE = 8191
|
37 |
LLM, EMBED_MODEL = get_service_provider_config(
|
38 |
service_provider=ServiceProvider.OPENAI, model_name=MODEL_NAME)
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
set_global_service_context(service_context)
|
45 |
|
46 |
|
47 |
class AwesumIndexBuilder(IndexBuilder):
|
@@ -108,13 +110,13 @@ class AwesumCareToolChatbot(Chatbot):
|
|
108 |
text_qa_template=CHAT_TEXT_QA_PROMPT)
|
109 |
|
110 |
def _setup_tools(self):
|
111 |
-
from llama_index.tools
|
112 |
self.tools = QueryEngineTool.from_defaults(
|
113 |
query_engine=self.query_engine)
|
114 |
return super()._setup_tools()
|
115 |
|
116 |
def _setup_chat_engine(self):
|
117 |
-
from llama_index.agent import OpenAIAgent
|
118 |
self.chat_engine = OpenAIAgent.from_tools(
|
119 |
tools=[self.tools],
|
120 |
llm=LLM,
|
@@ -151,22 +153,9 @@ index_builder = AwesumIndexBuilder(vdb_collection_name=VDB_COLLECTION_NAME,
|
|
151 |
is_load_from_vector_store=IS_LOAD_FROM_VECTOR_STORE)
|
152 |
|
153 |
# gpt-3.5-turbo-1106, gpt-4-1106-preview
|
154 |
-
awesum_chatbot = AwesumCareToolChatbot(model_name=model_name, index_builder=index_builder)
|
155 |
awesum_chatbot_context = AweSumCareContextChatbot(model_name=model_name, index_builder=index_builder)
|
156 |
-
awesum_chatbot_simple = AweSumCareSimpleChatbot(model_name=model_name, index_builder=index_builder)
|
157 |
-
|
158 |
-
|
159 |
-
def service_setup(model_name):
|
160 |
-
CHUNK_SIZE = 1024
|
161 |
-
LLM, EMBED_MODEL = get_service_provider_config(
|
162 |
-
service_provider=ServiceProvider.OPENAI, model_name=model_name)
|
163 |
-
service_context = ServiceContext.from_defaults(
|
164 |
-
chunk_size=CHUNK_SIZE,
|
165 |
-
llm=LLM,
|
166 |
-
embed_model=EMBED_MODEL,
|
167 |
-
)
|
168 |
-
set_global_service_context(service_context)
|
169 |
-
return LLM, EMBED_MODEL
|
170 |
|
171 |
chatbot = gr.Chatbot(height=500)
|
172 |
|
@@ -184,7 +173,7 @@ with gr.Blocks(fill_height=True) as demo:
|
|
184 |
with gr.Tab("With relevant context sent to system prompt"):
|
185 |
context_interface = gr.ChatInterface(
|
186 |
awesum_chatbot_context.stream_chat,
|
187 |
-
examples=
|
188 |
chatbot=chatbot
|
189 |
)
|
190 |
|
|
|
4 |
import os
|
5 |
from dotenv import load_dotenv
|
6 |
import phoenix as px
|
7 |
+
|
8 |
import llama_index
|
9 |
+
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
|
10 |
+
from llama_index.core.chat_engine.types import ChatMode
|
11 |
+
from llama_index.core.llms import ChatMessage, MessageRole
|
12 |
+
from llama_index.core.node_parser import SentenceSplitter
|
13 |
+
from llama_index.core.extractors import TitleExtractor
|
14 |
+
from llama_index.core.ingestion import IngestionPipeline
|
15 |
from llama_index.vector_stores.qdrant import QdrantVectorStore
|
16 |
+
|
17 |
+
from llama_index.llms.ollama import Ollama
|
18 |
+
|
19 |
from chat_template import CHAT_TEXT_QA_PROMPT, TEXT_QA_SYSTEM_PROMPT
|
20 |
from schemas import ChatbotVersion, ServiceProvider
|
21 |
from chatbot import Chatbot, IndexBuilder
|
22 |
from custom_io import MarkdownReader, UnstructuredReader, default_file_metadata_func
|
23 |
from qdrant import client as qdrantClient
|
24 |
+
from llama_index.core import set_global_service_context
|
25 |
|
26 |
from service_provider_config import get_service_provider_config
|
27 |
|
28 |
load_dotenv()
|
29 |
# initial service setup
|
30 |
px.launch_app()
|
31 |
+
llama_index.core.set_global_handler("arize_phoenix")
|
32 |
# llama_index.set_global_handler("wandb", run_args={"project": "llamaindex"})
|
33 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
34 |
|
|
|
36 |
VDB_COLLECTION_NAME = "demo-v6"
|
37 |
MODEL_NAME = ChatbotVersion.CHATGPT_4.value
|
38 |
|
|
|
39 |
CHUNK_SIZE = 8191
|
40 |
LLM, EMBED_MODEL = get_service_provider_config(
|
41 |
service_provider=ServiceProvider.OPENAI, model_name=MODEL_NAME)
|
42 |
+
|
43 |
+
LLM = Ollama(model="llama3.1:latest", request_timeout=60.0, context_window=10000)
|
44 |
+
|
45 |
+
Settings.embed_model = EMBED_MODEL
|
46 |
+
Settings.llm = LLM
|
|
|
47 |
|
48 |
|
49 |
class AwesumIndexBuilder(IndexBuilder):
|
|
|
110 |
text_qa_template=CHAT_TEXT_QA_PROMPT)
|
111 |
|
112 |
def _setup_tools(self):
|
113 |
+
from llama_index.core.tools import QueryEngineTool
|
114 |
self.tools = QueryEngineTool.from_defaults(
|
115 |
query_engine=self.query_engine)
|
116 |
return super()._setup_tools()
|
117 |
|
118 |
def _setup_chat_engine(self):
|
119 |
+
from llama_index.agent.openai import OpenAIAgent
|
120 |
self.chat_engine = OpenAIAgent.from_tools(
|
121 |
tools=[self.tools],
|
122 |
llm=LLM,
|
|
|
153 |
is_load_from_vector_store=IS_LOAD_FROM_VECTOR_STORE)
|
154 |
|
155 |
# gpt-3.5-turbo-1106, gpt-4-1106-preview
|
156 |
+
# awesum_chatbot = AwesumCareToolChatbot(model_name=model_name, index_builder=index_builder)
|
157 |
awesum_chatbot_context = AweSumCareContextChatbot(model_name=model_name, index_builder=index_builder)
|
158 |
+
# awesum_chatbot_simple = AweSumCareSimpleChatbot(model_name=model_name, index_builder=index_builder)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
160 |
chatbot = gr.Chatbot(height=500)
|
161 |
|
|
|
173 |
with gr.Tab("With relevant context sent to system prompt"):
|
174 |
context_interface = gr.ChatInterface(
|
175 |
awesum_chatbot_context.stream_chat,
|
176 |
+
examples=AwesumCareToolChatbot.CHAT_EXAMPLES,
|
177 |
chatbot=chatbot
|
178 |
)
|
179 |
|
chat_template.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
from llama_index.llms
|
2 |
-
from llama_index.
|
3 |
|
4 |
# text qa prompt
|
5 |
TEXT_QA_SYSTEM_PROMPT = ChatMessage(
|
|
|
1 |
+
from llama_index.core.llms import ChatMessage, MessageRole
|
2 |
+
from llama_index.core import ChatPromptTemplate
|
3 |
|
4 |
# text qa prompt
|
5 |
TEXT_QA_SYSTEM_PROMPT = ChatMessage(
|
chatbot.py
CHANGED
@@ -8,8 +8,7 @@ from dotenv import load_dotenv
|
|
8 |
from openai import OpenAI
|
9 |
import phoenix as px
|
10 |
import llama_index
|
11 |
-
from llama_index import
|
12 |
-
from llama_index.llms import ChatMessage, MessageRole
|
13 |
|
14 |
load_dotenv()
|
15 |
|
|
|
8 |
from openai import OpenAI
|
9 |
import phoenix as px
|
10 |
import llama_index
|
11 |
+
from llama_index.core.llms import ChatMessage, MessageRole
|
|
|
12 |
|
13 |
load_dotenv()
|
14 |
|
custom_io.py
CHANGED
@@ -11,8 +11,8 @@ from pathlib import Path
|
|
11 |
import re
|
12 |
from typing import Any, Dict, List, Optional
|
13 |
|
14 |
-
from llama_index.readers.base import BaseReader
|
15 |
-
from llama_index.
|
16 |
|
17 |
|
18 |
class UnstructuredReader(BaseReader):
|
|
|
11 |
import re
|
12 |
from typing import Any, Dict, List, Optional
|
13 |
|
14 |
+
from llama_index.core.readers.base import BaseReader
|
15 |
+
from llama_index.core import Document
|
16 |
|
17 |
|
18 |
class UnstructuredReader(BaseReader):
|
poetry.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|
pyproject.toml
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "awesumcare-demo"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = ""
|
5 |
+
authors = ["Ray Yip"]
|
6 |
+
readme = "README.md"
|
7 |
+
package-mode = false
|
8 |
+
|
9 |
+
[tool.poetry.dependencies]
|
10 |
+
python = ">=3.10,<3.13"
|
11 |
+
gradio = "^4.29.0"
|
12 |
+
llama-index = "^0.10.58"
|
13 |
+
nltk = "^3.8.1"
|
14 |
+
phoenix = "^0.9.1"
|
15 |
+
openai = "^1.37.0"
|
16 |
+
python-dotenv = "^1.0.1"
|
17 |
+
qdrant-client = "^1.10.1"
|
18 |
+
arize-phoenix = "^4.14.1"
|
19 |
+
fastapi = ">=0.80"
|
20 |
+
llama-index-vector-stores-qdrant = "^0.2.14"
|
21 |
+
llama-index-agent-openai = "^0.2.9"
|
22 |
+
llama-index-embeddings-azure-openai = "^0.1.11"
|
23 |
+
llama-index-embeddings-openai = "^0.1.11"
|
24 |
+
llama-index-llms-openai = "^0.1.27"
|
25 |
+
llama-index-callbacks-arize-phoenix = "^0.1.6"
|
26 |
+
llama-index-llms-ollama = "^0.2.0"
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
[build-system]
|
31 |
+
requires = ["poetry-core"]
|
32 |
+
build-backend = "poetry.core.masonry.api"
|
service_provider_config.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
from dotenv import load_dotenv
|
2 |
-
from llama_index import OpenAIEmbedding
|
3 |
-
from llama_index.llms import OpenAI
|
4 |
-
from llama_index.
|
5 |
-
from llama_index.embeddings import AzureOpenAIEmbedding
|
6 |
from schemas import ServiceProvider, ChatbotVersion
|
7 |
|
8 |
load_dotenv()
|
|
|
1 |
from dotenv import load_dotenv
|
2 |
+
from llama_index.embeddings.openai import OpenAIEmbedding
|
3 |
+
from llama_index.llms.openai import OpenAI
|
4 |
+
from llama_index.embeddings.azure_openai import AzureOpenAI
|
5 |
+
from llama_index.embeddings.azure_openai import AzureOpenAIEmbedding
|
6 |
from schemas import ServiceProvider, ChatbotVersion
|
7 |
|
8 |
load_dotenv()
|