236 lines
5.6 KiB
Plaintext
236 lines
5.6 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "b02n_zJ_hl3d"
|
|
},
|
|
"source": [
|
|
"## Cookbook for using Cohere with Embedchain"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "gyJ6ui2vhtMY"
|
|
},
|
|
"source": [
|
|
"### Step-1: Install embedchain package"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "-NbXjAdlh0vJ",
|
|
"outputId": "fae77912-4e6a-4c78-fcb7-fbbe46f7a9c7"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"!pip install embedchain[dataloaders,together]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "nGnpSYAAh2bQ"
|
|
},
|
|
"source": [
|
|
"### Step-2: Set Cohere related environment variables\n",
|
|
"\n",
|
|
"You can find `OPENAI_API_KEY` on your [OpenAI dashboard](https://platform.openai.com/account/api-keys) and `TOGETHER_API_KEY` key on your [Together dashboard](https://api.together.xyz/settings/api-keys)."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {
|
|
"id": "0fBdQ9GAiRvK"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"from embedchain import Pipeline as App\n",
|
|
"\n",
|
|
"os.environ[\"OPENAI_API_KEY\"] = \"\"\n",
|
|
"os.environ[\"TOGETHER_API_KEY\"] = \"\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "Ns6RhPfbiitr"
|
|
},
|
|
"source": [
|
|
"### Step-3: Define your llm and embedding model config"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {
|
|
"id": "S9CkxVjriotB"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"config = \"\"\"\n",
|
|
"llm:\n",
|
|
" provider: together\n",
|
|
" config:\n",
|
|
" model: mistralai/Mixtral-8x7B-Instruct-v0.1\n",
|
|
" temperature: 0.5\n",
|
|
" max_tokens: 1000\n",
|
|
"\"\"\"\n",
|
|
"\n",
|
|
"# Write the multi-line string to a YAML file\n",
|
|
"with open('together.yaml', 'w') as file:\n",
|
|
" file.write(config)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "PGt6uPLIi1CS"
|
|
},
|
|
"source": [
|
|
"### Step-4 Create embedchain app based on the config"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 321
|
|
},
|
|
"id": "Amzxk3m-i3tD",
|
|
"outputId": "afe8afde-5cb8-46bc-c541-3ad26cc3fa6e"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"app = App.from_config(config_path=\"together.yaml\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "XNXv4yZwi7ef"
|
|
},
|
|
"source": [
|
|
"### Step-5: Add data sources to your app"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 176
|
|
},
|
|
"id": "Sn_0rx9QjIY9",
|
|
"outputId": "2f2718a4-3b7e-4844-fd46-3e0857653ca0"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Inserting batches in chromadb: 100%|██████████| 1/1 [00:01<00:00, 1.16s/it]"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Successfully saved https://www.forbes.com/profile/elon-musk (DataType.WEB_PAGE). New chunks count: 4\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"'8cf46026cabf9b05394a2658bd1fe890'"
|
|
]
|
|
},
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"app.add(\"https://www.forbes.com/profile/elon-musk\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "_7W6fDeAjMAP"
|
|
},
|
|
"source": [
|
|
"### Step-6: All set. Now start asking questions related to your data"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "cvIK7dWRjN_f",
|
|
"outputId": "79e873c8-9594-45da-f5a3-0a893511267f"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"while(True):\n",
|
|
" question = input(\"Enter question: \")\n",
|
|
" if question in ['q', 'exit', 'quit']:\n",
|
|
" break\n",
|
|
" answer = app.query(question)\n",
|
|
" print(answer)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"colab": {
|
|
"provenance": []
|
|
},
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.11.4"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0
|
|
}
|