Skip to content

Commit

Permalink
ruff fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Nov 19, 2024
1 parent 0def6b6 commit 7d125a9
Show file tree
Hide file tree
Showing 32 changed files with 78 additions and 50 deletions.
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]
3 changes: 2 additions & 1 deletion examples/async/expert_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
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


Expand Down
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
Expand Down
3 changes: 2 additions & 1 deletion examples/decorator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from operator import itemgetter

from funcchain.syntax import chain, runnable
from langchain_community.embeddings import OpenAIEmbeddings
from langchain_community.vectorstores.faiss import FAISS
from langchain_core.runnables import Runnable, RunnablePassthrough

from funcchain.syntax import chain, runnable


@runnable
def generate_poem(topic: str, context: str) -> str:
Expand Down
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"

Expand Down
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:


Expand Down
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"
Expand Down
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
Expand Down
7 changes: 4 additions & 3 deletions examples/experiments/parallel_console_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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


Expand Down
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):
Expand Down
3 changes: 2 additions & 1 deletion examples/models/azure.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from funcchain import chain, settings
from pydantic import BaseModel, Field

from funcchain import chain, settings


# define your model
class SentimentAnalysis(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion examples/models/claude3.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Annotated

from funcchain import Depends, chain, settings
from langchain.document_loaders.pdf import PyPDFLoader

from funcchain import Depends, chain, settings

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


Expand Down
3 changes: 2 additions & 1 deletion examples/models/groq_models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from funcchain import chain, settings
from langchain_groq import ChatGroq
from pydantic import BaseModel, Field
from rich import print

from funcchain import chain, settings


class SentimentAnalysis(BaseModel):
analysis: str = Field(description="A description of the analysis")
Expand Down
3 changes: 2 additions & 1 deletion examples/models/llamacpp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from funcchain import chain, settings
from pydantic import BaseModel, Field
from rich import print

from funcchain import chain, settings


# define your model
class SentimentAnalysis(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion examples/models/ollama.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from funcchain import chain, settings
from pydantic import BaseModel, Field
from rich import print

from funcchain import chain, settings


# define your model
class SentimentAnalysis(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion examples/openai_json_mode.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


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

from funcchain import chain, settings

# settings.llm = "ollama/openchat"
settings.console_stream = True

Expand Down
5 changes: 3 additions & 2 deletions examples/rag_with_deps.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from operator import itemgetter
from typing import Annotated

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

from funcchain.syntax import chain, runnable
from funcchain.syntax.params import Depends

retriever = FAISS.from_texts(
[
"cold showers are good for your immune system",
Expand Down
3 changes: 2 additions & 1 deletion examples/simple/gather_infos.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.llm = "ollama/openchat"
settings.console_stream = True

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

from funcchain import achain, chain
from pydantic import BaseModel

from funcchain import achain, chain


class Task(BaseModel):
name: str
Expand Down
3 changes: 2 additions & 1 deletion examples/simple/tutorial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# %%
from funcchain import chain
from pydantic import BaseModel, Field, validator

from funcchain import chain


# %%
def say_hello(num: int) -> str:
Expand Down
3 changes: 2 additions & 1 deletion examples/static_router.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from enum import Enum
from typing import Any

from funcchain import chain, settings
from pydantic import BaseModel, Field

from funcchain import chain, settings

settings.console_stream = True
# settings.llm = "ollama/openhermes2.5-mistral"

Expand Down
5 changes: 3 additions & 2 deletions examples/stream_runnables.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from typing import AsyncIterator, Iterator

from langchain_core.messages import AIMessage, HumanMessage
from langchain_core.runnables import RunnableGenerator, RunnableSerializable

from funcchain import chain
from funcchain.syntax import runnable
from funcchain.syntax.components import RouterChat
from funcchain.syntax.components.handler import create_chat_handler
from funcchain.utils.msg_tools import msg_to_str
from langchain_core.messages import AIMessage, HumanMessage
from langchain_core.runnables import RunnableGenerator, RunnableSerializable

# settings.llm = "ollama/openchat"

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

from funcchain import chain


class Item(BaseModel):
name: str = Field(description="Name of the item")
Expand Down
3 changes: 2 additions & 1 deletion examples/vision.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from funcchain import Image, chain, settings
from pydantic import BaseModel, Field

from funcchain import Image, chain, settings

settings.llm = "openai/gpt-4-vision-preview"
# settings.llm = "ollama/bakllava"
settings.console_stream = True
Expand Down
6 changes: 2 additions & 4 deletions src/funcchain/syntax/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@
@overload
def runnable(
f: Callable[..., OutputT],
) -> Runnable[dict[str, Any], OutputT]:
...
) -> Runnable[dict[str, Any], OutputT]: ...


@overload
def runnable(
*,
llm: UniversalChatModel = None,
settings: SettingsOverride = {},
) -> Callable[[Callable[..., OutputT]], Runnable[dict[str, Any], OutputT]]:
...
) -> Callable[[Callable[..., OutputT]], Runnable[dict[str, Any], OutputT]]: ...


def runnable(
Expand Down
3 changes: 2 additions & 1 deletion tests/async_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
settings.llm = "openai/gpt-3.5-turbo-1106"

Expand Down
3 changes: 2 additions & 1 deletion tests/models/llamacpp_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
from funcchain import Image, chain, settings
from pydantic import BaseModel, Field

from funcchain import Image, chain, settings


class Task(BaseModel):
description: str
Expand Down
3 changes: 2 additions & 1 deletion tests/models/ollama_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
from funcchain import Image, chain, settings
from pydantic import BaseModel, Field

from funcchain import Image, chain, settings


class Task(BaseModel):
description: str
Expand Down
3 changes: 2 additions & 1 deletion tests/models/openai_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from funcchain import chain, settings
from pydantic import BaseModel, Field

from funcchain import chain, settings


class Task(BaseModel):
name: str
Expand Down

0 comments on commit 7d125a9

Please sign in to comment.