Skip to content

Commit

Permalink
Feature/move to langgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrichards4 authored Jul 30, 2024
2 parents 455c6f6 + 47412f9 commit 4513eed
Show file tree
Hide file tree
Showing 38 changed files with 3,113 additions and 2,422 deletions.
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,18 @@ rebuild: stop prune ## Rebuild all images

.PHONY: test-core-api
test-core-api: ## Test core-api
cp .env.test core-api/.env
cd core-api && poetry install --with dev && poetry run python -m pytest -m "not ai" --cov=core_api -v --cov-report=term-missing --cov-fail-under=75
cd core-api && poetry install --with dev && poetry run python -m pytest --cov=core_api -v --cov-report=term-missing --cov-fail-under=75

.PHONY: test-ai
test-ai: ## Test code with live LLM
cp .env.test core-api/.env
cd core-api && poetry install --with dev && poetry run python -m pytest -m "ai" --cov=core_api -v --cov-report=term-missing --cov-fail-under=80
cd redbox-core && poetry install --with dev && poetry run python -m pytest -m "ai" --cov=redbox -v --cov-report=term-missing --cov-fail-under=80

.PHONY: test-redbox
test-redbox: ## Test redbox
cp .env.test redbox-core/.env
cd redbox-core && poetry install && poetry run pytest --cov=redbox -v --cov-report=term-missing --cov-fail-under=60
cd redbox-core && poetry install && poetry run pytest -m "not ai" --cov=redbox -v --cov-report=term-missing --cov-fail-under=60

.PHONY: test-worker
test-worker: ## Test worker
cp .env.test worker/.env
cd worker && poetry install && poetry run pytest --cov=worker -v --cov-report=term-missing --cov-fail-under=80

.PHONY: test-django
Expand Down
281 changes: 0 additions & 281 deletions core-api/core_api/build_chains.py

This file was deleted.

17 changes: 13 additions & 4 deletions core-api/core_api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from functools import lru_cache
from typing import Annotated

from redbox import Redbox
import tiktoken
from fastapi import Depends
from langchain_community.chat_models import ChatLiteLLM
Expand All @@ -24,14 +25,12 @@ def get_env() -> Settings:
return Settings()


@lru_cache(1)
def get_embedding_model(env: Annotated[Settings, Depends(get_env)]) -> Embeddings:
return get_embeddings(env)


@lru_cache(1)
def get_parameterised_retriever(
env: Annotated[Settings, Depends(get_env)],
env: Annotated[Settings, Depends(get_env)], embeddings: Annotated[Embeddings, Depends(get_embedding_model)]
) -> BaseRetriever:
"""Creates an Elasticsearch retriever runnable.
Expand All @@ -50,7 +49,7 @@ def get_parameterised_retriever(
es_client=env.elasticsearch_client(),
index_name=f"{env.elastic_root_index}-chunk",
params=default_params,
embedding_model=get_embedding_model(env),
embedding_model=embeddings,
embedding_field_name=env.embedding_document_field_name,
).configurable_fields(
params=ConfigurableField(
Expand Down Expand Up @@ -109,3 +108,13 @@ def get_llm(env: Annotated[Settings, Depends(get_env)]) -> ChatLiteLLM:
@lru_cache(1)
def get_tokeniser() -> tiktoken.Encoding:
return tiktoken.get_encoding("cl100k_base")


def get_redbox(
llm: Annotated[ChatLiteLLM, Depends(get_llm)],
all_chunks_retriever: Annotated[AllElasticsearchRetriever, Depends(get_all_chunks_retriever)],
parameterised_retriever: Annotated[ParameterisedElasticsearchRetriever, Depends(get_parameterised_retriever)],
tokeniser: Annotated[tiktoken.Encoding, Depends(get_tokeniser)],
env: Annotated[Settings, Depends(get_env)],
) -> Redbox:
return Redbox(llm, all_chunks_retriever, parameterised_retriever, tokeniser, env)
Loading

0 comments on commit 4513eed

Please sign in to comment.