Skip to content

Commit

Permalink
Merge pull request #15 from Mirascope/openrouter-support
Browse files Browse the repository at this point in the history
feat: support for openrouter
  • Loading branch information
willbakst authored Oct 16, 2024
2 parents b797e49 + 495bca2 commit 0303f6a
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,27 @@ const EditorContainer = () => {
{ value: "o1-preview", label: "o1-preview" },
{ value: "o1-mini", label: "o1-mini" },
{ value: "gpt-4-turbo", label: "GPT-4 Turbo" },
{ value: "gpt-3.5-turbo", label: "GPT-3.5 Turbo" },
],
[Provider.ANTHROPIC]: [
{ value: "claude-3-5-sonnet-20240620", label: "Claude 3.5 Sonnet" },
{ value: "claude-3-opus-20240229", label: "Claude 3 Opus" },
{ value: "claude-3-sonnet-20240229", label: "Claude 3 Sonnet" },
{ value: "claude-3-haiku-20240307", label: "Claude 3 Haiku" },
],
[Provider.OPENROUTER]: [
{ value: "openai/chatgpt-4o-latest", label: "GPT-4o" },
{ value: "openai/gpt-4o-mini", label: "GPT-4o-mini" },
{ value: "openai/o1-preview", label: "o1-preview" },
{ value: "openai/o1-mini", label: "o1-mini" },
{ value: "openai/gpt-4-turbo", label: "GPT-4 Turbo" },
{
value: "anthropic/claude-3.5-sonnet",
label: "Claude 3.5 Sonnet",
},
{ value: "anthropic/claude-3-opus", label: "Claude 3 Opus" },
{ value: "anthropic/claude-3-sonnet", label: "Claude 3 Sonnet" },
{ value: "anthropic/claude-3-haiku", label: "Claude 3 Haiku" },
],
};

const options = modelOptions[provider] || [];
Expand Down Expand Up @@ -193,6 +206,7 @@ const EditorContainer = () => {
<SelectContent>
<SelectItem value="openai">OpenAI</SelectItem>
<SelectItem value="anthropic">Anthropic</SelectItem>
<SelectItem value="openrouter">OpenRouter</SelectItem>
</SelectContent>
</Select>
)}
Expand Down
1 change: 1 addition & 0 deletions client/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export interface ProjectTable {
export enum Provider {
OPENAI = "openai",
ANTHROPIC = "anthropic",
OPENROUTER = "openrouter",
}

/**
Expand Down
16 changes: 15 additions & 1 deletion lilypad/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,24 @@ def traced_synced_llm_function_constructor(
if not trace_decorator:
trace_decorator = lambda x: x # noqa: E731

provider = fn_params.provider.value

# Custom Clients
client = None
if fn_params.provider.value == "openrouter":
from openai import OpenAI

provider = "openai"
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key=os.getenv("OPENROUTER_API_KEY"),
)

call_decorator = partial(
import_module(f"mirascope.core.{fn_params.provider.value}").call,
import_module(f"mirascope.core.{provider}").call,
model=fn_params.model,
json_mode=False,
client=client,
)

def decorator(
Expand Down
2 changes: 0 additions & 2 deletions lilypad/cli/commands/run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""The `run` command, which runs a prompt with lilypad opentelemetry tracing."""

import json
import os
import runpy
from pathlib import Path

from rich import print
from typer import Argument, Option
Expand Down
1 change: 0 additions & 1 deletion lilypad/cli/commands/start.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""The `start` command to initialize Lilypad."""

import contextlib
import json
import os
import signal
import subprocess
Expand Down
1 change: 0 additions & 1 deletion lilypad/configure.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Initialize Lilypad OpenTelemetry instrumentation."""

import importlib.util
import os

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
Expand Down
2 changes: 0 additions & 2 deletions lilypad/server/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""Main FastAPI application module for Lilypad."""

import json
import os
from collections.abc import Sequence
from pathlib import Path
from typing import Annotated, Any

from fastapi import Depends, FastAPI, HTTPException, Request, status
Expand Down
1 change: 1 addition & 0 deletions lilypad/server/models/fn_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Provider(str, Enum):

OPENAI = "openai"
ANTHROPIC = "anthropic"
OPENROUTER = "openrouter"


class FnParamsBase(BaseSQLModel):
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "python-lilypad"
version = "0.0.3"
version = "0.0.4"
description = "An open-source prompt engineering framework."
readme = "README.md"
license = { file = "LICENSE" }
Expand Down Expand Up @@ -42,7 +42,7 @@ dependencies = [

[project.urls]
# Homepage = "https://mirascope.com/lilypad"
# Documentation = "https://lilypad.mirascope.com/docs"
Documentation = "https://lilypad.mirascope.com/docs"
Repository = "https://github.com/Mirascope/lilypad"
Issues = "https://github.com/Mirascope/lilypad/issues"
Changelog = "https://github.com/Mirascope/lilypad/releases"
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0303f6a

Please sign in to comment.