|
|
from transformers import pipeline |
|
|
import requests |
|
|
|
|
|
|
|
|
LANGSMITH_API_KEY = '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' |
|
|
LANGSMITH_ENDPOINT = 'https://smith.langchain.com/o/b7d2cb3f-e589-52bb-9b8a-2e8483e4ee8d/tailor' |
|
|
|
|
|
|
|
|
conversational_pipeline = pipeline('text-generation', model='facebook/blenderbot-3B') |
|
|
|
|
|
def tailor_with_langsmith(model_data): |
|
|
headers = { |
|
|
'Authorization': f'Bearer {LANGSMITH_API_KEY}', |
|
|
'Content-Type': 'application/json' |
|
|
} |
|
|
data = { |
|
|
'model_data': model_data |
|
|
} |
|
|
response = requests.post(LANGSMITH_ENDPOINT, json=data, headers=headers) |
|
|
response.raise_for_status() |
|
|
return response.json() |
|
|
|
|
|
def create_custom_conversation(prompt): |
|
|
|
|
|
hf_response = conversational_pipeline(prompt, max_length=50) |
|
|
hf_reply = hf_response[0]['generated_text'] |
|
|
|
|
|
|
|
|
tailored_response = tailor_with_langsmith({'model_data': hf_reply}) |
|
|
tailored_reply = tailored_response.get('tailored_reply', '') |
|
|
|
|
|
return tailored_reply |
|
|
|
|
|
if __name__ == '__main__': |
|
|
user_prompt = "Tell me about the latest advancements in AI." |
|
|
response = create_custom_conversation(user_prompt) |
|
|
print("Tailored Response:", response) |
|
|
|