Skip to content

Commit

Permalink
Use langchain voyage (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw authored Nov 8, 2023
1 parent 0ba841a commit d1de5c9
Show file tree
Hide file tree
Showing 5 changed files with 546 additions and 647 deletions.
5 changes: 3 additions & 2 deletions ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
from langchain.indexes import SQLRecordManager, index
from langchain.schema.embeddings import Embeddings
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.utils.html import PREFIXES_TO_IGNORE_REGEX, SUFFIXES_TO_IGNORE_REGEX
from langchain.utils.html import (PREFIXES_TO_IGNORE_REGEX,
SUFFIXES_TO_IGNORE_REGEX)
from langchain.vectorstores import Weaviate
from voyage import VoyageEmbeddings

from constants import WEAVIATE_DOCS_INDEX_NAME
from voyage import VoyageEmbeddings

logger = logging.getLogger(__name__)

Expand Down
22 changes: 10 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,27 @@

import langsmith
import weaviate
from constants import WEAVIATE_DOCS_INDEX_NAME
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from langchain.chat_models import ChatOpenAI
from langchain.embeddings import OpenAIEmbeddings
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder, PromptTemplate
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.embeddings.voyageai import VoyageEmbeddings
from langchain.prompts import (ChatPromptTemplate, MessagesPlaceholder,
PromptTemplate)
from langchain.schema import Document
from langchain.schema.embeddings import Embeddings
from langchain.schema.language_model import BaseLanguageModel
from langchain.schema.messages import AIMessage, HumanMessage
from langchain.schema.output_parser import StrOutputParser
from langchain.schema.retriever import BaseRetriever
from langchain.schema.runnable import (
Runnable,
RunnableBranch,
RunnableLambda,
RunnableMap,
)
from langchain.schema.runnable import (Runnable, RunnableBranch,
RunnableLambda, RunnableMap)
from langchain.vectorstores import Weaviate
from langserve import add_routes
from langsmith import Client
from pydantic import BaseModel
from voyage import VoyageEmbeddings

from constants import WEAVIATE_DOCS_INDEX_NAME

RESPONSE_TEMPLATE = """\
You are an expert programmer and problem-solver, tasked with answering any question \
Expand Down Expand Up @@ -97,8 +95,8 @@ class ChatRequest(BaseModel):


def get_embeddings_model() -> Embeddings:
if os.environ.get("VOYAGE_AI_URL") and os.environ.get("VOYAGE_AI_MODEL"):
return VoyageEmbeddings()
if os.environ.get("VOYAGE_API_KEY") and os.environ.get("VOYAGE_AI_MODEL"):
return VoyageEmbeddings(model=os.environ["VOYAGE_AI_MODEL"])
return OpenAIEmbeddings(chunk_size=200)


Expand Down
Loading

0 comments on commit d1de5c9

Please sign in to comment.