Skip to content

Conversation

@hinthornw
Copy link
Collaborator

No description provided.

SalehHindi and others added 3 commits June 30, 2023 08:14
# Description
Instead of inheriting off of LLM objects like OpenAI to create
PromptLayer objects (eg PromptLayerOpenAI), create a single
PromptLayerCallback object. This adds support for all of langchain's
LLMs (openai, anthropic, replicate, dozens others).

This also paves the way for PromptLayer to add logging for agents,
chains, etc based on the callbacks api.

## Examples

Async Example
```python
import asyncio
openai_llm = OpenAI(
    model_name="text-davinci-002",
    callbacks=[PromptLayerHandler(
        request_id_func = request_id_func,
        pl_tags = ["openai_1!"]
    )]
)
asyncio.run(async_generate(openai_llm))

```


Replicate LLM Example
```python
# Test Replicate LLM
replicate_llm = Replicate(
    model="replicate/dolly-v2-12b:ef0e1aefc61f8e096ebe4db6b2bacc297daf2ef6899f0f7e001ec445893500e5",
    callbacks=[PromptLayerHandler(
        request_id_func = request_id_func,
        pl_tags = ["replicate_example"]
    )]
)
llm_results = replicate_llm.generate([
    "Tell me a joke 1",
    "Where is Ohio? 2",
    "Where is Ohio? 3",
])

```

Chat Model Example w/ Streaming (works w/o streaming as well)
```python
# Test OpenAIChat LLM
chat_llm = ChatOpenAI(
    temperature=0,
    streaming=True.
    callbacks=[PromptLayerHandler(
        request_id_func = request_id_func,
        pl_tags = ["chatopenai"]
    )]
)
llm_results = chat_llm([
    HumanMessage(content="What comes after 1,2,3 ?"),
    HumanMessage(content="Tell me another joke?"),
])
```

TODO:
- Add documentation + sample notebook
- Might also want to test streaming works

<!--
Thank you for contributing to LangChain! Your PR will appear in our
release under the title you set. Please make sure it highlights your
valuable contribution.

Replace this with a description of the change, the issue it fixes (if
applicable), and relevant context. List any dependencies required for
this change.

After you're done, someone will review your PR. They may suggest
improvements. If no one reviews your PR within a few days, feel free to
@-mention the same people again, as notifications can get lost.

Finally, we'd love to show appreciation for your contribution - if you'd
like us to shout you out on Twitter, please also include your handle!
-->

<!-- Remove if not applicable -->

#### Before submitting

<!-- If you're adding a new integration, please include:

1. a test for the integration - favor unit tests that does not rely on
network access.
2. an example notebook showing its use


See contribution guidelines for more information on how to write tests,
lint
etc:


https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
-->

#### Who can review?

Tag maintainers/contributors who might be interested:

<!-- For a quicker response, figure out the right person to tag with @

  @hwchase17 - project lead

  Tracing / Callbacks
  - @agola11

  Async
  - @agola11

  DataLoaders
  - @eyurtsev

  Models
  - @hwchase17
  - @agola11

  Agents / Tools / Toolkits
  - @hwchase17

  VectorStores / Retrievers / Memory
  - @dev2049

 -->

---------

Co-authored-by: jped <[email protected]>
@vercel
Copy link

vercel bot commented Jun 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
langchain ⬜️ Ignored (Inspect) Jun 30, 2023 3:19pm

@hinthornw hinthornw merged commit 64039b9 into master Jun 30, 2023
@hinthornw hinthornw deleted the wfh/add_promptlayer_callback branch June 30, 2023 15:32
vowelparrot pushed a commit that referenced this pull request Jul 4, 2023
Co-authored-by: Saleh Hindi <[email protected]>
Co-authored-by: jped <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants