Skip to content

Commit

Permalink
bedrock langchain (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyliu513 authored Aug 16, 2024
1 parent 9fd1944 commit 6c46d41
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
2 changes: 0 additions & 2 deletions aws/bedrock1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


from dotenv import load_dotenv
load_dotenv()

Expand Down
27 changes: 27 additions & 0 deletions aws/langchain-bedrock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'''
(titan) gyliu@Guangyas-MacBook-Air .aws % cat credentials
[bedrock-admin]
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
(titan) gyliu@Guangyas-MacBook-Air .aws % pwd
/Users/gyliu/.aws
'''

from dotenv import load_dotenv
load_dotenv()

from traceloop.sdk import Traceloop
from traceloop.sdk.decorators import task, workflow

Traceloop.init(app_name="joke_generation_service")

from langchain_aws import BedrockLLM

llm = BedrockLLM(
credentials_profile_name="bedrock-admin",
model_id="amazon.titan-text-express-v1",
region_name="us-west-2",
)

print(llm.invoke(input="What is the recipe of mayonnaise?"))
32 changes: 32 additions & 0 deletions haystack/hay-chat-bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from dotenv import load_dotenv
load_dotenv()

from haystack.telemetry import tutorial_running

tutorial_running(40)
'''
from haystack.dataclasses import ChatMessage
from haystack.components.generators.chat import OpenAIChatGenerator
messages = [
ChatMessage.from_system("Always respond in German even if some input data is in other languages."),
ChatMessage.from_user("What's Natural Language Processing? Be brief."),
]
chat_generator = OpenAIChatGenerator(model="gpt-3.5-turbo")
chat_generator.run(messages=messages)
'''
'''
from haystack.dataclasses import ChatMessage
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.components.generators.utils import print_streaming_chunk
messages = [
ChatMessage.from_system("Always respond in German even if some input data is in other languages."),
ChatMessage.from_user("What's Natural Language Processing? Be brief."),
]
chat_generator = OpenAIChatGenerator(model="gpt-3.5-turbo", streaming_callback=print_streaming_chunk)
response = chat_generator.run(messages=messages)
print(response)
'''

0 comments on commit 6c46d41

Please sign in to comment.