You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Personally, I think that having proper documentation and tutorial is key, but this could provide a low-hanging-fruit kind of way to let users know how to use our tools + it can be automatically re-indexed.
I gave it a quick try. It's not bad, but would need more time to get it working fully. Also, writing more docstrings across the codebases would help a lot:
Code to reproduce:
importosimportopenaiimportchainlitasclfromllama_index.coreimport (
Settings,
StorageContext,
VectorStoreIndex,
load_index_from_storage,
)
fromllama_index.llms.openaiimportOpenAIfromllama_index.embeddings.openaiimportOpenAIEmbeddingfromllama_index.core.query_engine.retriever_query_engineimportRetrieverQueryEnginefromdotenvimportload_dotenvfromllama_index.coreimportVectorStoreIndexfromllama_index.readers.githubimportGithubRepositoryReader, GithubClientimportosload_dotenv()
Settings.llm=OpenAI(
model="gpt-4o",
temperature=0.1,
max_tokens=4096,
streaming=True,
system_prompt="""You are assistant helping to build prediction market agents.Agents are based on the PMAT (prediction-market-agent-tooling) library with implementations in PMA (prediction-market-agent repository).Assume that any question is in context of prediction market agent building.""",
)
Settings.embed_model=OpenAIEmbedding(model="text-embedding-3-large")
Settings.context_window=8196try:
storage_context=StorageContext.from_defaults(persist_dir="./storage")
index=load_index_from_storage(storage_context)
except:
github_token=os.environ.get("GITHUB_TOKEN")
owner="gnosis"github_client=GithubClient(github_token=github_token)
documents_pmat=GithubRepositoryReader(
github_client=github_client,
owner=owner,
repo="prediction-market-agent-tooling",
filter_directories=(
[
"prediction_market_agent_tooling",
"tests",
"tests_integration",
"tests_integration_with_local_chain",
],
GithubRepositoryReader.FilterType.INCLUDE,
),
).load_data(branch="main")
documents_pma=GithubRepositoryReader(
github_client=github_client,
owner=owner,
repo="prediction-market-agent",
filter_directories=(
[
"prediction_market_agent",
"tests",
],
GithubRepositoryReader.FilterType.INCLUDE,
),
).load_data(branch="main")
all_documents=documents_pmat+documents_pmaindex=VectorStoreIndex.from_documents(all_documents)
index.storage_context.persist("./storage")
@cl.on_chat_startasyncdefstart():
query_engine=index.as_query_engine(
streaming=True,
similarity_top_k=5,
)
cl.user_session.set("query_engine", query_engine)
awaitcl.Message(
author="Assistant", content="Hello! Im an AI assistant. How may I help you?"
).send()
@cl.on_messageasyncdefmain(message: cl.Message):
query_engine=cl.user_session.get("query_engine") # type: RetrieverQueryEnginemsg=cl.Message(content="", author="Assistant")
res=awaitcl.make_async(query_engine.query)(message.content)
fortokeninres.response_gen:
awaitmsg.stream_token(token)
awaitmsg.send()
Personally, I think that having proper documentation and tutorial is key, but this could provide a low-hanging-fruit kind of way to let users know how to use our tools + it can be automatically re-indexed.
https://github.com/Chainlit/chainlit
The text was updated successfully, but these errors were encountered: