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

feat(agents-api): Add embed_instruction argument to embeddings & document creation endpoints #715

Merged
merged 9 commits into from
Oct 22, 2024
Merged
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
61 changes: 28 additions & 33 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,34 @@

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<h3>📖 目录</h3>

- [简介](#introduction)
- [主要特点](#key-features)
- [快速示例](#quick-example)
- [安装](#安装)
- [Python 快速入门 🐍](#python-quick-start-)
- [Node.js 快速入门🟩](#nodejs-quick-start-)
- [步骤 1:创建代理](#step-1-create-an-agent)
- [组件](#components)
- [心智模型](#mental-model)
- [概念](#concepts)
- [理解任务](#understanding-tasks)
- [任务的生命周期](#lifecycle-of-a-task)
- [工作流步骤的类型](#types-of-workflow-steps)
- [工具类型](#tool-types)
- [用户定义的`函数`](#user-defined-functions)
- [`系统` 工具](#system-tools)
- [内置 `integrations`](#built-in-integrations)
-[直接`api_calls`](#direct-api_calls)
- [集成](#integrations)
- [其他功能](#other-features)
- [向代理添加工具](#adding-tools-to-agents)
- [管理会话和用户](#managing-sessions-and-users)
- [文档集成与搜索](#document-integration-and-search)
- [参考](#reference)
- [SDK 参考](#sdk-reference)
- [API 参考](#api-reference)
- [本地快速启动](#local-quickstart)
- [Julep 和 LangChain 等有什么区别?](#julep 和 langchain 等之间有什么区别)
- [不同用例](#different-use-cases)
- [不同的外形尺寸](#different-form-factor)
- [总结](#in-summary)
<h3>📖 Table of Contents</h3>

- [主要特点](#%E4%B8%BB%E8%A6%81%E7%89%B9%E7%82%B9)
- [Python 快速入门🐍](#python-%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8)
- [Node.js Quick Start 🟩](#nodejs-quick-start-)
- [Step 1: Create an Agent](#step-1-create-an-agent)
- [Components](#components)
- [Mental Model](#mental-model)
- [Concepts](#concepts)
- [Understanding Tasks](#understanding-tasks)
- [Lifecycle of a Task](#lifecycle-of-a-task)
- [Types of Workflow Steps](#types-of-workflow-steps)
- [Tool Types](#tool-types)
- [User-defined `functions`](#user-defined-functions)
- [`system` tools](#system-tools)
- [Built-in `integrations`](#built-in-integrations)
- [Direct `api_calls`](#direct-api_calls)
- [Integrations](#integrations)
- [Other Features](#other-features)
- [Adding Tools to Agents](#adding-tools-to-agents)
- [Managing Sessions and Users](#managing-sessions-and-users)
- [Document Integration and Search](#document-integration-and-search)
- [SDK 参考](#sdk-%E5%8F%82%E8%80%83)
- [API 参考](#api-%E5%8F%82%E8%80%83)
- [本地快速启动](#%E6%9C%AC%E5%9C%B0%E5%BF%AB%E9%80%9F%E5%90%AF%E5%8A%A8)
- [Julep 和 LangChain 等有什么区别?](#julep-%E5%92%8C-langchain-%E7%AD%89%E6%9C%89%E4%BB%80%E4%B9%88%E5%8C%BA%E5%88%AB)
- [不同的用例](#%E4%B8%8D%E5%90%8C%E7%9A%84%E7%94%A8%E4%BE%8B)
- [不同的外形尺寸](#%E4%B8%8D%E5%90%8C%E7%9A%84%E5%A4%96%E5%BD%A2%E5%B0%BA%E5%AF%B8)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down
60 changes: 30 additions & 30 deletions README-FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,39 @@ Des nouvelles passionnantes ! Nous participons au DevFest.AI tout au long du moi

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<h3>📖 Table des matières</h3>
<h3>📖 Table of Contents</h3>

- [Présentation](#introduction)
- [Caractéristiques principales](#key-features)
- [Exemple rapide](#quick-example)
- [Introduction](#introduction)
- [Principales caractéristiques](#principales-caract%C3%A9ristiques)
- [Exemple rapide](#exemple-rapide)
- [Installation](#installation)
- [Démarrage rapide de Python 🐍](#python-quick-start-)
- [Démarrage rapide de Node.js 🟩](#nodejs-quick-start-)
- [Étape 1 : Créer un agent](#step-1-create-an-agent)
- [Composants](#composants)
- [Modèle mental](#mental-model)
- [Démarrage rapide de Python 🐍](#d%C3%A9marrage-rapide-de-python-)
- [Node.js Quick Start 🟩](#nodejs-quick-start-)
- [Step 1: Create an Agent](#step-1-create-an-agent)
- [Components](#components)
- [Mental Model](#mental-model)
- [Concepts](#concepts)
- [Comprendre les tâches](#understanding-tasks)
- [Cycle de vie d'une tâche](#cycle-de-vie-d-une-tâche)
- [Types d'étapes de flux de travail](#types-of-workflow-steps)
- [Types d'outils](#types-d'outils)
- [`Fonctions` définies par l'utilisateur](#user-defined-functions)
- [outils système](#outils-système)
- [`Intégrations` intégrées](#integrations-integrées)
- [Appels directs `api_calls`](#appels directs-api_calls)
- [Intégrations](#intégrations)
- [Autres fonctionnalités](#other-features)
- [Ajout d'outils aux agents](#adding-tools-to-agents)
- [Gestion des sessions et des utilisateurs](#managing-sessions-and-users)
- [Intégration et recherche de documents](#document-integration-and-search)
- [Référence](#référence)
- [Référence SDK](#sdk-reference)
- [Référence API](#api-reference)
- [Démarrage rapide local](#local-quickstart)
- [Quelle est la différence entre Julep et LangChain etc ?](#quelle-est-la-différence-entre-julep-et-langchain-etc)
- [Différents cas d'utilisation](#different-use-cases)
- [Facteur de forme différent](#different-form-factor)
- [En résumé](#en-resumé)
- [Understanding Tasks](#understanding-tasks)
- [Lifecycle of a Task](#lifecycle-of-a-task)
- [Types of Workflow Steps](#types-of-workflow-steps)
- [Tool Types](#tool-types)
- [User-defined `functions`](#user-defined-functions)
- [`system` tools](#system-tools)
- [Built-in `integrations`](#built-in-integrations)
- [Direct `api_calls`](#direct-api_calls)
- [Integrations](#integrations)
- [Other Features](#other-features)
- [Adding Tools to Agents](#adding-tools-to-agents)
- [Managing Sessions and Users](#managing-sessions-and-users)
- [Document Integration and Search](#document-integration-and-search)
- [Référence](#r%C3%A9f%C3%A9rence)
- [Référence du SDK](#r%C3%A9f%C3%A9rence-du-sdk)
- [Référence API](#r%C3%A9f%C3%A9rence-api)
- [Démarrage rapide local](#d%C3%A9marrage-rapide-local)
- [Quelle est la différence entre Julep et LangChain etc ?](#quelle-est-la-diff%C3%A9rence-entre-julep-et-langchain-etc-)
- [Différents cas d'utilisation](#diff%C3%A9rents-cas-dutilisation)
- [Facteur de forme différent](#facteur-de-forme-diff%C3%A9rent)
- [En résumé](#en-r%C3%A9sum%C3%A9)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down
63 changes: 30 additions & 33 deletions README-JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,36 @@ Julep プロジェクトに新しい貢献者を迎えられることを嬉し

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
<h3>📖 目次</h3>

- [はじめに](#introduction)
- [主な特徴](#key-features)
- [簡単な例](#quick-example)
- [インストール](#installation)
- [Python クイックスタート 🐍](#python-quick-start-)
- [Node.js クイック スタート 🟩](#nodejs-quick-start-)
- [ステップ 1: エージェントを作成する](#step-1-create-an-agent)
- [コンポーネント](#components)
- [メンタルモデル](#mental-model)
- [コンセプト](#concepts)
- [タスクの理解](#understanding-tasks)
- [タスクのライフサイクル](#lifecycle-of-a-task)
- [ワークフロー ステップの種類](#types-of-workflow-steps)
- [ツールの種類](#tool-types)
- [ユーザー定義の `functions`](#user-defined-functions)
- [`システム` ツール](#system-tools)
- [組み込みの `integrations`](#built-in-integrations)
- [直接の `api_calls`](#direct-api_calls)
- [統合](#integrations)
- [その他の機能](#other-features)
- [エージェントへのツールの追加](#adding-tools-to-agents)
- [セッションとユーザーの管理](#managing-sessions-and-users)
- [ドキュメントの統合と検索](#document-integration-and-search)
- [参考](#reference)
- [SDKリファレンス](#sdk-reference)
- [APIリファレンス](#api-reference)
- [ローカルクイックスタート](#local-quickstart)
- [Julep と LangChain などの違いは何ですか?](#whats-the-difference-between-julep-and-langchain-etc)
- [さまざまなユースケース](#different-use-cases)
- [異なるフォームファクター](#different-form-factor)
- [要約](#in-summary)
<h3>📖 Table of Contents</h3>

- [主な特徴](#%E4%B8%BB%E3%81%AA%E7%89%B9%E5%BE%B4)
- [簡単な例](#%E7%B0%A1%E5%8D%98%E3%81%AA%E4%BE%8B)
- [インストール](#%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB)
- [Python クイックスタート 🐍](#python-%E3%82%AF%E3%82%A4%E3%83%83%E3%82%AF%E3%82%B9%E3%82%BF%E3%83%BC%E3%83%88-)
- [Node.js Quick Start 🟩](#nodejs-quick-start-)
- [Step 1: Create an Agent](#step-1-create-an-agent)
- [Components](#components)
- [Mental Model](#mental-model)
- [Concepts](#concepts)
- [Understanding Tasks](#understanding-tasks)
- [Lifecycle of a Task](#lifecycle-of-a-task)
- [Types of Workflow Steps](#types-of-workflow-steps)
- [Tool Types](#tool-types)
- [User-defined `functions`](#user-defined-functions)
- [`system` tools](#system-tools)
- [Built-in `integrations`](#built-in-integrations)
- [Direct `api_calls`](#direct-api_calls)
- [Integrations](#integrations)
- [Other Features](#other-features)
- [Adding Tools to Agents](#adding-tools-to-agents)
- [Managing Sessions and Users](#managing-sessions-and-users)
- [Document Integration and Search](#document-integration-and-search)
- [SDK リファレンス](#sdk-%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9)
- [API リファレンス](#api-%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9)
- [ローカルクイックスタート](#%E3%83%AD%E3%83%BC%E3%82%AB%E3%83%AB%E3%82%AF%E3%82%A4%E3%83%83%E3%82%AF%E3%82%B9%E3%82%BF%E3%83%BC%E3%83%88)
- [Julep と LangChain などの違いは何ですか?](#julep-%E3%81%A8-langchain-%E3%81%AA%E3%81%A9%E3%81%AE%E9%81%95%E3%81%84%E3%81%AF%E4%BD%95%E3%81%A7%E3%81%99%E3%81%8B)
- [さまざまなユースケース](#%E3%81%95%E3%81%BE%E3%81%96%E3%81%BE%E3%81%AA%E3%83%A6%E3%83%BC%E3%82%B9%E3%82%B1%E3%83%BC%E3%82%B9)
- [異なるフォームファクタ](#%E7%95%B0%E3%81%AA%E3%82%8B%E3%83%95%E3%82%A9%E3%83%BC%E3%83%A0%E3%83%95%E3%82%A1%E3%82%AF%E3%82%BF)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down
8 changes: 8 additions & 0 deletions agents-api/agents_api/autogen/Docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class CreateDocRequest(BaseModel):
"""
Contents of the document
"""
embed_instruction: str | None = None
"""
Instruction for the embedding model.
"""


class Doc(BaseModel):
Expand Down Expand Up @@ -113,6 +117,10 @@ class EmbedQueryRequest(BaseModel):
"""
Text or texts to embed
"""
embed_instruction: str = ""
"""
Instruction for the embedding model.
"""


class EmbedQueryResponse(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions agents-api/agents_api/models/docs/create_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def create_doc(
data.metadata = data.metadata or {}

doc_data = data.model_dump()
doc_data.pop("embed_instruction", None)
content = doc_data.pop("content")

doc_data["owner_type"] = owner_type
Expand Down
11 changes: 7 additions & 4 deletions agents-api/agents_api/routers/docs/create_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from temporalio.client import Client as TemporalClient

from ...activities.types import EmbedDocsPayload
from ...autogen.openapi_model import CreateDocRequest, ResourceCreatedResponse
from ...autogen.openapi_model import CreateDocRequest, Doc, ResourceCreatedResponse
from ...clients import temporal
from ...common.retry_policies import DEFAULT_RETRY_POLICY
from ...dependencies.developer_id import get_developer_id
Expand All @@ -21,6 +21,7 @@ async def run_embed_docs_task(
doc_id: UUID,
title: str,
content: list[str],
embed_instruction: str | None = None,
job_id: UUID,
background_tasks: BackgroundTasks,
client: TemporalClient | None = None,
Expand All @@ -34,7 +35,7 @@ async def run_embed_docs_task(
doc_id=doc_id,
content=content,
title=title,
embed_instruction=None,
embed_instruction=embed_instruction,
)

handle = await client.start_workflow(
Expand All @@ -60,7 +61,7 @@ async def create_user_doc(
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
background_tasks: BackgroundTasks,
) -> ResourceCreatedResponse:
doc = create_doc_query(
doc: Doc = create_doc_query(
developer_id=x_developer_id,
owner_type="user",
owner_id=user_id,
Expand All @@ -74,6 +75,7 @@ async def create_user_doc(
doc_id=doc.id,
title=doc.title,
content=doc.content,
embed_instruction=data.embed_instruction,
job_id=embed_job_id,
background_tasks=background_tasks,
)
Expand All @@ -90,7 +92,7 @@ async def create_agent_doc(
x_developer_id: Annotated[UUID, Depends(get_developer_id)],
background_tasks: BackgroundTasks,
) -> ResourceCreatedResponse:
doc = create_doc_query(
doc: Doc = create_doc_query(
developer_id=x_developer_id,
owner_type="agent",
owner_id=agent_id,
Expand All @@ -104,6 +106,7 @@ async def create_agent_doc(
doc_id=doc.id,
title=doc.title,
content=doc.content,
embed_instruction=data.embed_instruction,
job_id=embed_job_id,
background_tasks=background_tasks,
)
Expand Down
5 changes: 3 additions & 2 deletions agents-api/agents_api/routers/docs/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ async def embed(
text_to_embed: list[str] = (
[text_to_embed] if isinstance(text_to_embed, str) else text_to_embed
)

vectors = await litellm.aembedding(inputs=text_to_embed)
vectors = await litellm.aembedding(
inputs=[data.embed_instruction + text for text in text_to_embed]
)

return EmbedQueryResponse(vectors=vectors)
2 changes: 1 addition & 1 deletion agents-api/notebooks/RecSum-experiments.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"\n",
"\n",
"def chat():\n",
" while (user_input := input(\"You: \").lower()) != \"bye\": \n",
" while (user_input := input(\"You: \").lower()) != \"bye\":\n",
" chat_session.append(user(user_input))\n",
"\n",
" result = generate(chat_session)\n",
Expand Down
Loading
Loading