Created
September 28, 2023 18:38
-
-
Save thoraxe/0d495bbf6403b9676fc55e476b95f263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import llama_index | |
from llama_index import ( | |
SimpleDirectoryReader, | |
VectorStoreIndex, | |
StorageContext, | |
load_index_from_storage, | |
) | |
from llama_index.vector_stores import RedisVectorStore | |
from llama_index.tools import QueryEngineTool, ToolMetadata | |
from model_context import get_falcon_tgis_context | |
import os | |
llama_index.set_global_handler("simple") | |
redis_hostname = os.getenv('REDIS_SERVER_HOSTNAME', 'localhost') # Get server url from env else default | |
print("Connecting to Redis at " + redis_hostname) | |
vector_store = RedisVectorStore( | |
index_name="web-console", | |
redis_url=f"redis://{redis_hostname}:6379", | |
overwrite=False, | |
) | |
storage_context = StorageContext.from_defaults(vector_store=vector_store) | |
service_context = get_falcon_tgis_context(0.7, 1.03) | |
docs_index = VectorStoreIndex.from_vector_store(vector_store, service_context=service_context) | |
docs_engine = docs_index.as_query_engine(similarity_top_k=3) | |
query_engine_tools = [ | |
QueryEngineTool( | |
query_engine=docs_engine, | |
metadata=ToolMetadata( | |
name="docs_engine", | |
description="Provides information from the OpenShift documentation" | |
"Use a detailed plain text question as input to the tool.", | |
), | |
) | |
] | |
from llama_index.agent import ReActAgent | |
from llama_index.llms import LangChainLLM | |
from langchain import HuggingFaceTextGenInference | |
server_url = os.getenv('TGIS_SERVER_URL', 'http://localhost') # Get server url from env else default | |
server_port = os.getenv('TGIS_SERVER_PORT', '8049') # Get server port from env else default | |
inference_server_url=f"{server_url}:{server_port}/" | |
llm = LangChainLLM( | |
llm=HuggingFaceTextGenInference( | |
inference_server_url=inference_server_url, | |
max_new_tokens=256, | |
temperature=temperature, | |
repetition_penalty=repetition_penalty, | |
server_kwargs={}, | |
), | |
) | |
agent = ReActAgent.from_tools(query_engine_tools, llm=llm, verbose=True) | |
response = agent.chat("How do I replace the API server certificate?") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment