Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix import for promptlayer #134

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 0 additions & 19 deletions buster/completers/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import io
import logging
import os
import warnings
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from typing import Any, Iterator, Optional

import openai
Expand All @@ -16,23 +14,6 @@
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

# Check if an API key exists for promptlayer, if it does, use it
promptlayer_api_key = os.environ.get("PROMPTLAYER_API_KEY")
if promptlayer_api_key:
try:
import promptlayer

logger.info("Enabling prompt layer...")
promptlayer.api_key = promptlayer_api_key

# replace openai with the promptlayer wrapper
openai = promptlayer.openai
except Exception as e:
logger.exception("Something went wrong enabling promptlayer.")

# Set openai credentials
openai.api_key = os.environ.get("OPENAI_API_KEY")


class Completion:
def __init__(
Expand Down
19 changes: 19 additions & 0 deletions buster/completers/chatgpt.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import logging
import os
from typing import Iterator

import openai

from buster.completers import Completer

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

# Check if an API key exists for promptlayer, if it does, use it
promptlayer_api_key = os.environ.get("PROMPTLAYER_API_KEY")
if promptlayer_api_key:
try:
import promptlayer

logger.info("Enabling prompt layer...")
promptlayer.api_key = promptlayer_api_key

# replace openai with the promptlayer wrapper
openai = promptlayer.openai
except Exception as e:
logger.exception("Something went wrong enabling promptlayer.")


class ChatGPTCompleter(Completer):
def complete(self, prompt: str, user_input, completion_kwargs=None) -> str | Iterator:
Expand Down
Loading