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 canopy example #84

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions canopy-chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: 'Chat with Canopy'
tags: ['pinecone', 'chainlit', 'canopy']
---

# Chat your Canopy Server

This folder contains an example application that demonstrates how to:
- Connect to a running Canopy Server.
- Answer user queries using the data stored in the Pinecone database, and provide the sources for the answers.

## High-Level Description

The application uses the the Canopy-API Server. After you vectorised your index in Pinecone and have a running Canopy-Server you can start chatting with Pinecone RAG-Pipeline using OpenAI as LLM.

## Quickstart

To run the example, ensure you have a running Canopy-Server. Follow these steps:

1. Install the required dependencies by running `pip install -r requirements.txt` in your terminal.
2. Set your Canopy-API-URL into the `base_url`.
3. Run the application with `chainlit run app.py --port 8081`.
42 changes: 42 additions & 0 deletions canopy-chat/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from openai import AsyncOpenAI
import chainlit as cl

client = AsyncOpenAI(base_url="http://localhost:8000/v1", api_key=None)


settings = {
"model": "gpt-3.5-turbo",
"temperature": 0.7,
"max_tokens": 500,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
}


@cl.on_chat_start
def start_chat():
cl.user_session.set(
"message_history",
[{"role": "system", "content": "You are a helpful assistant."}],
)


@cl.on_message
async def main(message: cl.Message):
message_history = cl.user_session.get("message_history")
message_history.append({"role": "user", "content": message.content})

msg = cl.Message(content="")
await msg.send()

stream = await client.chat.completions.create(
messages=message_history, stream=True, **settings
)

async for part in stream:
if token := part.choices[0].delta.content or "":
await msg.stream_token(token)

message_history.append({"role": "assistant", "content": msg.content})
await msg.update()
Empty file added canopy-chat/chainlit.md
Empty file.
4 changes: 4 additions & 0 deletions canopy-chat/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pinecone-client==2.2.1
tiktoken==0.3.3
langchain
chainlit