Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: shroominic/funcchain
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.2.3
Choose a base ref
...
head repository: shroominic/funcchain
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Feb 15, 2024

  1. Copy the full SHA
    dae1a38 View commit details
  2. ✨ Add RAG example script

    shroominic committed Feb 15, 2024
    Copy the full SHA
    37b6b14 View commit details
  3. Copy the full SHA
    cd526af View commit details
  4. 🚀 Bump version to 0.3.0

    shroominic committed Feb 15, 2024
    Copy the full SHA
    a45f896 View commit details
  5. Copy the full SHA
    3b625fe View commit details
  6. Copy the full SHA
    c52a34b View commit details
  7. Copy the full SHA
    ba4e966 View commit details
  8. Copy the full SHA
    a722f61 View commit details
  9. Copy the full SHA
    f8ad19a View commit details
  10. 🏎️ update roadmap

    shroominic committed Feb 15, 2024
    Copy the full SHA
    cba0a5e View commit details

Commits on Feb 17, 2024

  1. Copy the full SHA
    ede1a24 View commit details
  2. Copy the full SHA
    f69a6de View commit details
  3. Copy the full SHA
    908a7cf View commit details
  4. Copy the full SHA
    224fa72 View commit details
  5. 🔄 Update import paths

    shroominic committed Feb 17, 2024
    Copy the full SHA
    bbc77e7 View commit details
  6. Copy the full SHA
    3d5beb3 View commit details
  7. Copy the full SHA
    4d948fa View commit details
  8. Copy the full SHA
    1dbdc17 View commit details
  9. 🔄 Update import path

    shroominic committed Feb 17, 2024
    Copy the full SHA
    e581086 View commit details
  10. 🔄 Refactor import paths

    shroominic committed Feb 17, 2024
    Copy the full SHA
    7b4ac45 View commit details
  11. ✨ Add chat model patches

    shroominic committed Feb 17, 2024
    Copy the full SHA
    63e5fb2 View commit details
  12. ✨ Add Azure chat wrapper

    shroominic committed Feb 17, 2024
    Copy the full SHA
    9319d58 View commit details
  13. Copy the full SHA
    6efee85 View commit details
  14. Copy the full SHA
    7815353 View commit details
  15. Copy the full SHA
    6c542d4 View commit details
  16. 📝 fix format

    shroominic committed Feb 17, 2024
    Copy the full SHA
    d4875fb View commit details

Commits on Mar 10, 2024

  1. Copy the full SHA
    83cd6f8 View commit details
  2. Copy the full SHA
    54704fb View commit details
  3. Copy the full SHA
    95ee96d View commit details
  4. Copy the full SHA
    312a74f View commit details
  5. Copy the full SHA
    436f6c7 View commit details
  6. Copy the full SHA
    f2fa148 View commit details
  7. 🔧 fix fix fix

    shroominic committed Mar 10, 2024
    Copy the full SHA
    8f2ecbc View commit details
  8. ✨ ruff fmt

    shroominic committed Mar 10, 2024
    Copy the full SHA
    ae2fc0d View commit details
  9. 📜 small fix in docs

    shroominic committed Mar 10, 2024
    Copy the full SHA
    a3b968b View commit details

Commits on Mar 17, 2024

  1. 🔧 fix typing

    shroominic committed Mar 17, 2024
    Copy the full SHA
    5e446b6 View commit details

Commits on Apr 11, 2024

  1. ✨llm override for chain

    shroominic committed Apr 11, 2024
    Copy the full SHA
    062a182 View commit details

Commits on Apr 20, 2024

  1. Copy the full SHA
    7c860c9 View commit details

Commits on May 17, 2024

  1. 🔧 fix need of pil dep

    shroominic committed May 17, 2024
    Copy the full SHA
    2b5fec2 View commit details
  2. Copy the full SHA
    c7504e4 View commit details
  3. 🔧 rm need of PIL dep

    shroominic committed May 17, 2024
    Copy the full SHA
    1814615 View commit details

Commits on Jun 15, 2024

  1. mv model examples

    shroominic committed Jun 15, 2024
    Copy the full SHA
    06741bf View commit details
  2. Copy the full SHA
    38dcee4 View commit details
  3. azure example for testing

    shroominic committed Jun 15, 2024
    Copy the full SHA
    f6e3f6b View commit details
  4. add groq and azure

    shroominic committed Jun 15, 2024
    Copy the full SHA
    04e1574 View commit details
  5. rm streaming

    shroominic committed Jun 15, 2024
    Copy the full SHA
    fb05ca5 View commit details
  6. Copy the full SHA
    d0dbc04 View commit details
  7. Copy the full SHA
    005e053 View commit details
  8. fix azure

    shroominic committed Jun 15, 2024
    Copy the full SHA
    5ac03b3 View commit details
  9. azure + groq

    shroominic committed Jun 15, 2024
    Copy the full SHA
    9f2954c View commit details
Showing with 1,031 additions and 308 deletions.
  1. +2 −0 .gitignore
  2. +12 −12 .pre-commit-config.yaml
  3. +3 −4 CONTRIBUTING.md
  4. +1 −1 MODELS.md
  5. +0 −46 dev-setup.sh
  6. +42 −0 docs/concepts/dependencies.md
  7. +1 −1 docs/concepts/langchain.md
  8. +1 −1 docs/getting-started/config.md
  9. +1 −1 docs/getting-started/models.md
  10. +2 −1 examples/async/expert_answer.py
  11. +2 −1 examples/async/startup_names.py
  12. +2 −1 examples/custom_model_display.py
  13. +7 −4 examples/decorator.py
  14. +2 −1 examples/dict_type.py
  15. +2 −1 examples/dynamic_router.py
  16. +2 −1 examples/enums.py
  17. +2 −1 examples/error_output.py
  18. +4 −3 examples/experiments/parallel_console_streaming.py
  19. +2 −1 examples/jinja.py
  20. +2 −1 examples/literals.py
  21. +30 −0 examples/models/azure.py
  22. +1 −0 examples/{ → models}/chatgpt.py
  23. +27 −0 examples/models/claude3.py
  24. +28 −0 examples/models/groq_models.py
  25. +2 −1 examples/{ → models}/llamacpp.py
  26. +2 −1 examples/{ → models}/ollama.py
  27. +2 −1 examples/openai_json_mode.py
  28. +2 −1 examples/pydantic_validation.py
  29. +35 −0 examples/rag_with_deps.py
  30. +22 −0 examples/runnable_deps.py
  31. +2 −1 examples/simple/gather_infos.py
  32. +2 −1 examples/simple/task_comparison.py
  33. +2 −1 examples/simple/tutorial.py
  34. +2 −1 examples/static_router.py
  35. +3 −2 examples/stream_runnables.py
  36. +2 −1 examples/union_types.py
  37. +2 −1 examples/vision.py
  38. +1 −0 mkdocs.yml
  39. +25 −12 pyproject.toml
  40. +422 −78 requirements-dev.lock
  41. +85 −34 requirements.lock
  42. +3 −3 roadmap.todo
  43. +2 −0 src/funcchain/__init__.py
  44. +57 −7 src/funcchain/backend/compiler.py
  45. +12 −2 src/funcchain/backend/prompt.py
  46. +15 −2 src/funcchain/backend/settings.py
  47. +28 −4 src/funcchain/model/abilities.py
  48. +35 −11 src/funcchain/model/defaults.py
  49. +7 −0 src/funcchain/model/patches/__init__.py
  50. +3 −3 src/funcchain/model/patches/llamacpp.py
  51. +2 −2 src/funcchain/model/patches/ollama.py
  52. +4 −3 src/funcchain/parser/primitive_types.py
  53. +2 −2 src/funcchain/schema/signature.py
  54. +3 −5 src/funcchain/schema/types.py
  55. +2 −2 src/funcchain/syntax/__init__.py
  56. +17 −25 src/funcchain/syntax/components/handler.py
  57. +3 −3 src/funcchain/syntax/components/router.py
  58. +2 −4 src/funcchain/syntax/decorators.py
  59. +7 −1 src/funcchain/syntax/executable.py
  60. +4 −2 src/funcchain/syntax/input_types.py
  61. +20 −0 src/funcchain/syntax/params.py
  62. +3 −3 src/funcchain/utils/image.py
  63. +1 −2 src/funcchain/utils/memory.py
  64. +2 −1 tests/async_test.py
  65. +2 −1 tests/models/llamacpp_test.py
  66. +2 −1 tests/models/ollama_test.py
  67. +2 −1 tests/models/openai_test.py
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ MANIFEST
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# *.lock

# Installer logs
pip-log.txt
@@ -166,3 +167,4 @@ cython_debug/
vscext
.models
.python-version
codrvenv
24 changes: 12 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
types_or: [python, pyi, jupyter]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
types_or: [python, pyi, jupyter]
7 changes: 3 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -3,9 +3,8 @@
To contribute, clone the repo and run:

```bash
./dev_setup.sh
rye sync
```

You should not run unstrusted scripts so ask ChatGPT to explain what the contents of this script do!

This will install and setup your development environment using [rye](https://rye-up.com) or pip.
You need to have rye installed, you can install it [here](https://rye-up.com/install)
This will install and setup your development environment using [rye](https://rye-up.com).
2 changes: 1 addition & 1 deletion MODELS.md
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
You can set the `settings.llm` with any LangChain ChatModel.

```python
from langchain_openai.chat_models import AzureChatOpenAI
from langchain_community.chat_models import AzureChatOpenAI

settings.llm = AzureChatOpenAI(...)
```
46 changes: 0 additions & 46 deletions dev-setup.sh

This file was deleted.

42 changes: 42 additions & 0 deletions docs/concepts/dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Dependencies

TODO: Write a docs for dependencies

## Example: RAG

```python
from operator import itemgetter
from typing import Annotated

from funcchain.syntax import chain, runnable
from funcchain.syntax.params import Depends
from langchain_community.vectorstores.faiss import FAISS
from langchain_community.embeddings import OpenAIEmbeddings

retriever = FAISS.from_texts(
[
"cold showers are good for your immune system",
"i dont like when people are mean to me",
"japanese tea is full of heart warming flavors",
],
embedding=OpenAIEmbeddings(),
).as_retriever(
search_kwargs={"k": 1},
)


@runnable
def poem_with_retrieval(
topic: str,
context: Annotated[str, Depends(itemgetter("topic") | retriever)] = "N/A",
) -> str:
"""
Generate a poem about the topic with the given context.
"""
return chain()


print(
poem_with_retrieval.invoke({"topic": "love"}),
)
```
2 changes: 1 addition & 1 deletion docs/concepts/langchain.md
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ This will convert your function into a runnable that can be used in LCEL so you
from funcchain import chain, runnable
from langchain_community.vectorstores.faiss import FAISS
from langchain_core.runnables import Runnable, RunnablePassthrough
from langchain_openai.embeddings import OpenAIEmbeddings
from langchain_community.embeddings import OpenAIEmbeddings

@runnable
def generate_poem(topic: str, context: str) -> str:
2 changes: 1 addition & 1 deletion docs/getting-started/config.md
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ def analyse_output(
result = analyse_output(
"healthy outpout",
"Hello World!",
settings_override={"llm": "openai/gpt-4-vision-preview"},
settings={"llm": "openai/gpt-4-vision-preview"},
)
```

2 changes: 1 addition & 1 deletion docs/getting-started/models.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ You can set the `settings.llm` with any LangChain ChatModel.

```python
from funcchain import settings
from langchain_openai.chat_models import AzureChatOpenAI
from langchain_community.chat_models import AzureChatOpenAI

settings.llm = AzureChatOpenAI(...)
```
3 changes: 2 additions & 1 deletion examples/async/expert_answer.py
Original file line number Diff line number Diff line change
@@ -2,9 +2,10 @@
from asyncio import run as _await
from random import shuffle

from funcchain import achain, settings
from pydantic import BaseModel

from funcchain import achain, settings

settings.temperature = 1


3 changes: 2 additions & 1 deletion examples/async/startup_names.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import asyncio

from funcchain import achain, settings
from pydantic import BaseModel

from funcchain import achain, settings

settings.temperature = 1


3 changes: 2 additions & 1 deletion examples/custom_model_display.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from funcchain import chain
from pydantic import BaseModel

from funcchain import chain


class Task(BaseModel):
name: str
11 changes: 7 additions & 4 deletions examples/decorator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from funcchain.syntax import chain, runnable
from operator import itemgetter

from langchain_community.embeddings import OpenAIEmbeddings
from langchain_community.vectorstores.faiss import FAISS
from langchain_core.runnables import Runnable, RunnablePassthrough
from langchain_openai.embeddings import OpenAIEmbeddings

from funcchain.syntax import chain, runnable


@runnable
@@ -23,8 +26,8 @@ def generate_poem(topic: str, context: str) -> str:
retriever = vectorstore.as_retriever(search_kwargs={"k": 1})

retrieval_chain: Runnable = {
"context": retriever,
"context": itemgetter("topic") | retriever,
"topic": RunnablePassthrough(),
} | generate_poem

print(retrieval_chain.invoke("love"))
print(retrieval_chain.invoke({"topic": "love"}))
3 changes: 2 additions & 1 deletion examples/dict_type.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from funcchain import chain, settings
from pydantic import BaseModel

from funcchain import chain, settings

settings.console_stream = True
settings.llm = "llamacpp/openchat-3.5-0106:Q3_K_M"

3 changes: 2 additions & 1 deletion examples/dynamic_router.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from enum import Enum
from typing import Any, Callable, TypedDict

from funcchain.syntax.executable import compile_runnable
from pydantic import BaseModel, Field

from funcchain.syntax.executable import compile_runnable

# Dynamic Router Definition:


3 changes: 2 additions & 1 deletion examples/enums.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from enum import Enum

from funcchain import chain
from pydantic import BaseModel

from funcchain import chain


class Answer(str, Enum):
yes = "yes"
3 changes: 2 additions & 1 deletion examples/error_output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from funcchain import BaseModel, Error, chain
from rich import print

from funcchain import BaseModel, Error, chain


class User(BaseModel):
name: str
7 changes: 4 additions & 3 deletions examples/experiments/parallel_console_streaming.py
Original file line number Diff line number Diff line change
@@ -3,14 +3,15 @@
from typing import AsyncGenerator
from uuid import uuid4

from funcchain import achain, settings
from funcchain.backend.streaming import astream_to
from funcchain.utils.token_counter import count_tokens
from rich.console import Console
from rich.layout import Layout
from rich.live import Live
from rich.panel import Panel

from funcchain import achain, settings
from funcchain.backend.streaming import astream_to
from funcchain.utils.token_counter import count_tokens


class RenderChain:
def __init__(self, renderer: "Renderer", name: str) -> None:
3 changes: 2 additions & 1 deletion examples/jinja.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from funcchain import chain, settings
from pydantic import BaseModel

from funcchain import chain, settings

settings.console_stream = True


3 changes: 2 additions & 1 deletion examples/literals.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Literal

from funcchain import chain
from pydantic import BaseModel

from funcchain import chain


# just a silly example to schowcase the Literal type
class Ranking(BaseModel):
30 changes: 30 additions & 0 deletions examples/models/azure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from pydantic import BaseModel, Field

from funcchain import chain, settings


# define your model
class SentimentAnalysis(BaseModel):
analysis: str = Field(description="A description of the analysis")
sentiment: bool = Field(description="True for Happy, False for Sad")


# define your prompt
def analyze(text: str) -> SentimentAnalysis:
"""
Determines the sentiment of the text.
"""
return chain()


if __name__ == "__main__":
# set global llm
settings.llm = "azure/gpt-4o"
# log tokens as stream to console
settings.console_stream = True

# run prompt
poem = analyze("I really like when my dog does a trick!")

# show final parsed output
print(poem)
1 change: 1 addition & 0 deletions examples/chatgpt.py → examples/models/chatgpt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Simple chatgpt rebuild with memory/history.
"""

from funcchain import chain, settings
from funcchain.utils.memory import ChatMessageHistory

27 changes: 27 additions & 0 deletions examples/models/claude3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import Annotated

from langchain.document_loaders.pdf import PyPDFLoader

from funcchain import Depends, chain, settings

settings.llm = "anthropic/claude-3-opus-20240229"


def load_pdf(input: dict) -> str:
if path := input.get("path"):
return " ".join([d.page_content for d in PyPDFLoader(path).load()])
return "No URL given"


def summarize_pdf(path: str, pdf: Annotated[str, Depends(load_pdf)] = "") -> str:
"""
Given the full pdf summarize the entire document and focus on the most important parts.
"""
return chain()


path = "~/Downloads/muzio1966.pdf"

summary = summarize_pdf(path)

print(summary)
Loading