Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenAI GPT-4 Plugin for Steamship
# LiteLLM Plugin for Steamship for OpenAI compatibility

This plugin provides access to OpenAI's GPT-4 language model for text generation.
This plugin provides access to LiteLLM's language model translation to OpenAI format for text generation.

## Usage

Expand All @@ -11,8 +11,8 @@ Use of this plugin is subject to OpenAI's [Terms of Use](https://openai.com/poli
#### Basic

```python
gpt4 = steamship.use_plugin("gpt-4")
task = gpt4.generate(text=prompt)
litellm = steamship.use_plugin("litellm")
task = litellm.generate(text=prompt)
task.wait()
for block in task.output.blocks:
print(block.text)
Expand All @@ -21,16 +21,16 @@ for block in task.output.blocks:
#### With Runtime Parameters

```python
gpt4 = steamship.use_plugin("gpt-4")
task = gpt4.generate(text=prompt, options={"stop": ["6", "7"]})
litellm = steamship.use_plugin("litellm")
task = litellm.generate(text=prompt, options={"stop": ["6", "7"]})
task.wait()
for block in task.output.blocks:
print(block.text)
```

## Cost

[Pricing page](https://www.steamship.com/plugins/gpt-4?tab=Pricing)
[Pricing page](https://www.steamship.com/plugins/litellm?tab=Pricing)


## Developing this Plugin
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
openai==0.27.8
tenacity==8.2.2
steamship==2.17.31
litellm
13 changes: 7 additions & 6 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
]


class GPT4Plugin(StreamingGenerator):
class LiteLLMPlugin(StreamingGenerator):
"""
Plugin for generating text using OpenAI's GPT-4 model.
Plugin for generating text using LiteLLM-supported models.
"""

class GPT4PluginConfig(Config):
class LiteLLMPluginConfig(Config):
openai_api_key: str = Field(
"",
description="An openAI API key to use. If left default, will use Steamship's API key.",
Expand Down Expand Up @@ -113,9 +113,9 @@ class GPT4PluginConfig(Config):

@classmethod
def config_cls(cls) -> Type[Config]:
return cls.GPT4PluginConfig
return cls.LiteLLMPluginConfig

config: GPT4PluginConfig
config: LiteLLMPluginConfig

def __init__(
self,
Expand Down Expand Up @@ -200,8 +200,9 @@ def generate_with_retry(
output_blocks: List[Block],
) -> List[UsageReport]:
"""Call the API to generate the next section of text."""
# TODO Fix
logging.info(
f"Making OpenAI GPT-4 chat completion call on behalf of user with id: {user}"
f"Making LiteLLM call on behalf of user with id: {user}"
)
options = options or {}
stopwords = options.get("stop", None)
Expand Down
110 changes: 0 additions & 110 deletions steamship.json

This file was deleted.

27 changes: 13 additions & 14 deletions test/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
"""Test gpt-4 generation via integration tests."""
import json
from typing import Optional

import pytest
from steamship import Block, File, Steamship, MimeTypes, Tag
from steamship.data import TagKind
from steamship.data.tags.tag_constants import RoleTag, TagValueKey

GENERATOR_HANDLE = "gpt-4"
GENERATOR_HANDLE = "litellm"

@pytest.mark.parametrize(
"model", ["", "gpt-4-32k", "gpt-4-1106-preview"]
)
def test_generator(model: str):
with Steamship.temporary_workspace() as steamship:
gpt4 = steamship.use_plugin(GENERATOR_HANDLE, config={"model": model})
litellm = steamship.use_plugin(GENERATOR_HANDLE, config={"model": model})
file = File.create(
steamship,
blocks=[
Expand All @@ -31,7 +30,7 @@ def test_generator(model: str):
],
)

generate_task = gpt4.generate(input_file_id=file.id)
generate_task = litellm.generate(input_file_id=file.id)
generate_task.wait()
output = generate_task.output
assert len(output.blocks) == 1
Expand All @@ -42,22 +41,22 @@ def test_generator(model: str):

def test_generator_without_role():
with Steamship.temporary_workspace() as steamship:
gpt4 = steamship.use_plugin(GENERATOR_HANDLE)
litellm = steamship.use_plugin(GENERATOR_HANDLE)
file = File.create(
steamship,
blocks=[
Block(text="1 2 3 4"),
],
)
generate_task = gpt4.generate(input_file_id=file.id)
generate_task = litellm.generate(input_file_id=file.id)
generate_task.wait()
output = generate_task.output
assert len(output.blocks) == 1


def test_stopwords():
with Steamship.temporary_workspace() as steamship:
gpt4 = steamship.use_plugin(GENERATOR_HANDLE)
litellm = steamship.use_plugin(GENERATOR_HANDLE)
file = File.create(
steamship,
blocks=[
Expand All @@ -73,7 +72,7 @@ def test_stopwords():
),
],
)
generate_task = gpt4.generate(
generate_task = litellm.generate(
input_file_id=file.id, options={"stop": ["6", "7"]}
)
generate_task.wait()
Expand All @@ -85,7 +84,7 @@ def test_stopwords():

def test_functions():
with Steamship.temporary_workspace() as steamship:
gpt4 = steamship.use_plugin(GENERATOR_HANDLE)
litellm = steamship.use_plugin(GENERATOR_HANDLE)
file = File.create(
steamship,
blocks=[
Expand All @@ -101,7 +100,7 @@ def test_functions():
),
],
)
generate_task = gpt4.generate(
generate_task = litellm.generate(
input_file_id=file.id,
options={
"functions": [
Expand Down Expand Up @@ -129,7 +128,7 @@ def test_functions():

def test_multimodal_functions_with_blocks():
with Steamship.temporary_workspace() as steamship:
gpt4 = steamship.use_plugin(GENERATOR_HANDLE)
litellm = steamship.use_plugin(GENERATOR_HANDLE)
file = File.create(
steamship,
blocks=[
Expand Down Expand Up @@ -161,7 +160,7 @@ def test_multimodal_functions_with_blocks():
),
],
)
generate_task = gpt4.generate(
generate_task = litellm.generate(
input_file_id=file.id,
options={
"functions": [
Expand Down Expand Up @@ -220,7 +219,7 @@ def test_multimodal_functions_with_blocks():

def test_functions_function_message():
with Steamship.temporary_workspace() as steamship:
gpt4 = steamship.use_plugin(GENERATOR_HANDLE)
litellm = steamship.use_plugin(GENERATOR_HANDLE)

file = File.create(
steamship,
Expand Down Expand Up @@ -248,7 +247,7 @@ def test_functions_function_message():
],
)

generate_task = gpt4.generate(
generate_task = litellm.generate(
input_file_id=file.id,
options={
"functions": [
Expand Down
Loading