Skip to content

Commit

Permalink
chore: ensure imports and __all__s are sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Dec 30, 2024
1 parent 6032351 commit 42d80aa
Show file tree
Hide file tree
Showing 25 changed files with 66 additions and 65 deletions.
1 change: 1 addition & 0 deletions examples/async-chat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio

from ollama import AsyncClient


Expand Down
1 change: 1 addition & 0 deletions examples/async-generate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio

import ollama


Expand Down
4 changes: 3 additions & 1 deletion examples/async-structured-outputs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import asyncio

from pydantic import BaseModel

from ollama import AsyncClient
import asyncio


# Define the schema for the response
Expand Down
3 changes: 2 additions & 1 deletion examples/async-tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
from ollama import ChatResponse

import ollama
from ollama import ChatResponse


def add_two_numbers(a: int, b: int) -> int:
Expand Down
1 change: 0 additions & 1 deletion examples/chat-stream.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from ollama import chat


messages = [
{
'role': 'user',
Expand Down
1 change: 0 additions & 1 deletion examples/chat-with-history.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from ollama import chat


messages = [
{
'role': 'user',
Expand Down
1 change: 0 additions & 1 deletion examples/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from ollama import create


args = sys.argv[1:]
if len(args) == 2:
# create from local file
Expand Down
1 change: 0 additions & 1 deletion examples/generate-stream.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ollama import generate


for part in generate('llama3.2', 'Why is the sky blue?', stream=True):
print(part['response'], end='', flush=True)
1 change: 0 additions & 1 deletion examples/generate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ollama import generate


response = generate('llama3.2', 'Why is the sky blue?')
print(response['response'])
3 changes: 1 addition & 2 deletions examples/list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ollama import list
from ollama import ListResponse
from ollama import ListResponse, list

response: ListResponse = list()

Expand Down
1 change: 1 addition & 0 deletions examples/multimodal-chat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ollama import chat

# from pathlib import Path

# Pass in the path to the image
Expand Down
4 changes: 2 additions & 2 deletions examples/multimodal-generate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sys
import random
import sys

import httpx

from ollama import generate


latest = httpx.get('https://xkcd.com/info.0.json')
latest.raise_for_status()

Expand Down
3 changes: 1 addition & 2 deletions examples/ps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ollama import ps, pull, chat
from ollama import ProcessResponse
from ollama import ProcessResponse, chat, ps, pull

# Ensure at least one model is loaded
response = pull('llama3.2', stream=True)
Expand Down
2 changes: 1 addition & 1 deletion examples/pull.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from tqdm import tqdm
from ollama import pull

from ollama import pull

current_digest, bars = '', {}
for progress in pull('llama3.2', stream=True):
Expand Down
4 changes: 3 additions & 1 deletion examples/structured-outputs-image.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path
from pydantic import BaseModel
from typing import Literal

from pydantic import BaseModel

from ollama import chat


Expand Down
3 changes: 2 additions & 1 deletion examples/structured-outputs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ollama import chat
from pydantic import BaseModel

from ollama import chat


# Define the schema for the response
class FriendInfo(BaseModel):
Expand Down
3 changes: 1 addition & 2 deletions examples/tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ollama import chat
from ollama import ChatResponse
from ollama import ChatResponse, chat


def add_two_numbers(a: int, b: int) -> int:
Expand Down
38 changes: 19 additions & 19 deletions ollama/__init__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
from ollama._client import Client, AsyncClient
from ollama._client import AsyncClient, Client
from ollama._types import (
Options,
Message,
Image,
Tool,
GenerateResponse,
ChatResponse,
EmbedResponse,
EmbeddingsResponse,
StatusResponse,
ProgressResponse,
EmbedResponse,
GenerateResponse,
Image,
ListResponse,
ShowResponse,
Message,
Options,
ProcessResponse,
ProgressResponse,
RequestError,
ResponseError,
ShowResponse,
StatusResponse,
Tool,
)

__all__ = [
'Client',
'AsyncClient',
'Options',
'Message',
'Image',
'Tool',
'GenerateResponse',
'ChatResponse',
'Client',
'EmbedResponse',
'EmbeddingsResponse',
'StatusResponse',
'ProgressResponse',
'GenerateResponse',
'Image',
'ListResponse',
'ShowResponse',
'Message',
'Options',
'ProcessResponse',
'ProgressResponse',
'RequestError',
'ResponseError',
'ShowResponse',
'StatusResponse',
'Tool',
]

_client = Client()
Expand Down
22 changes: 9 additions & 13 deletions ollama/_client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
import io
import ipaddress
import json
import os
import platform
import ipaddress
import sys
import urllib.parse
from hashlib import sha256
from os import PathLike
from pathlib import Path
from hashlib import sha256

from typing import (
Any,
Callable,
Expand All @@ -21,17 +21,14 @@
overload,
)

import sys

from pydantic.json_schema import JsonSchemaValue


from ollama._utils import convert_function_to_tool

if sys.version_info < (3, 9):
from typing import Iterator, AsyncIterator
from typing import AsyncIterator, Iterator
else:
from collections.abc import Iterator, AsyncIterator
from collections.abc import AsyncIterator, Iterator

from importlib import metadata

Expand All @@ -45,13 +42,13 @@
from ollama._types import (
ChatRequest,
ChatResponse,
CreateRequest,
CopyRequest,
CreateRequest,
DeleteRequest,
EmbedRequest,
EmbedResponse,
EmbeddingsRequest,
EmbeddingsResponse,
EmbedRequest,
EmbedResponse,
GenerateRequest,
GenerateResponse,
Image,
Expand All @@ -70,7 +67,6 @@
Tool,
)


T = TypeVar('T')


Expand Down
9 changes: 4 additions & 5 deletions ollama/_types.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import json
from base64 import b64decode, b64encode
from pathlib import Path
from datetime import datetime
from typing import Any, Mapping, Optional, Union, Sequence

from pydantic.json_schema import JsonSchemaValue
from typing_extensions import Annotated, Literal
from pathlib import Path
from typing import Any, Mapping, Optional, Sequence, Union

from pydantic import (
BaseModel,
Expand All @@ -14,6 +11,8 @@
Field,
model_serializer,
)
from pydantic.json_schema import JsonSchemaValue
from typing_extensions import Annotated, Literal


class SubscriptableBaseModel(BaseModel):
Expand Down
6 changes: 4 additions & 2 deletions ollama/_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations
from collections import defaultdict

import inspect
from typing import Callable, Union
import re
from collections import defaultdict
from typing import Callable, Union

import pydantic

from ollama._types import Tool


Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ select = [
"E", # pycodestyle errors
"F", # pyflakes
"B", # bugbear (likely bugs)
"I", # sort imports
"RUF022", # sort __all__
]
ignore = [
"E111", # indentation not a multiple of four
Expand Down
11 changes: 6 additions & 5 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import base64
import os
import json
from pydantic import ValidationError, BaseModel
import pytest
import os
import tempfile
from pathlib import Path

import pytest
from pydantic import BaseModel, ValidationError
from pytest_httpserver import HTTPServer, URIPattern
from werkzeug.wrappers import Request, Response

from ollama._client import Client, AsyncClient, _copy_tools
from ollama._client import AsyncClient, Client, _copy_tools

PNG_BASE64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGNgYGAAAAAEAAH2FzhVAAAAAElFTkSuQmCC'
PNG_BYTES = base64.b64decode(PNG_BASE64)
Expand Down Expand Up @@ -91,7 +92,7 @@ def generate():
@pytest.mark.parametrize('message_format', ('dict', 'pydantic_model'))
@pytest.mark.parametrize('file_style', ('path', 'bytes'))
def test_client_chat_images(httpserver: HTTPServer, message_format: str, file_style: str, tmp_path):
from ollama._types import Message, Image
from ollama._types import Image, Message

httpserver.expect_ordered_request(
'/api/chat',
Expand Down
3 changes: 2 additions & 1 deletion tests/test_type_serialization.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import tempfile
from base64 import b64encode
from pathlib import Path

import pytest

from ollama._types import Image
import tempfile


def test_image_serialization_bytes():
Expand Down
3 changes: 1 addition & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys
from typing import Dict, List, Mapping, Sequence, Set, Tuple, Union


from ollama._utils import convert_function_to_tool


Expand Down Expand Up @@ -118,7 +117,7 @@ def all_types(


def test_function_docstring_parsing():
from typing import List, Dict, Any
from typing import Any, Dict, List

def func_with_complex_docs(x: int, y: List[str]) -> Dict[str, Any]:
"""
Expand Down

0 comments on commit 42d80aa

Please sign in to comment.