Update app.py
Browse files
app.py
CHANGED
|
@@ -3,10 +3,10 @@ import requests
|
|
| 3 |
|
| 4 |
# Replace with your actual LangSmith API key
|
| 5 |
LANGSMITH_API_KEY = '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'
|
| 6 |
-
LANGSMITH_ENDPOINT = 'https://smith.langchain.com/o/b7d2cb3f-e589-52bb-9b8a-2e8483e4ee8d/
|
| 7 |
|
| 8 |
-
# Initialize the Hugging Face
|
| 9 |
-
conversational_pipeline = pipeline('
|
| 10 |
|
| 11 |
def tailor_with_langsmith(model_data):
|
| 12 |
headers = {
|
|
@@ -22,11 +22,11 @@ def tailor_with_langsmith(model_data):
|
|
| 22 |
|
| 23 |
def create_custom_conversation(prompt):
|
| 24 |
# Step 1: Get response from Hugging Face model
|
| 25 |
-
hf_response = conversational_pipeline(prompt)
|
| 26 |
hf_reply = hf_response[0]['generated_text']
|
| 27 |
|
| 28 |
# Step 2: Tailor the response using LangSmith
|
| 29 |
-
tailored_response = tailor_with_langsmith(hf_reply)
|
| 30 |
tailored_reply = tailored_response.get('tailored_reply', '')
|
| 31 |
|
| 32 |
return tailored_reply
|
|
|
|
| 3 |
|
| 4 |
# Replace with your actual LangSmith API key
|
| 5 |
LANGSMITH_API_KEY = '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'
|
| 6 |
+
LANGSMITH_ENDPOINT = 'https://smith.langchain.com/o/b7d2cb3f-e589-52bb-9b8a-2e8483e4ee8d/tailor' # Make sure this is the correct endpoint
|
| 7 |
|
| 8 |
+
# Initialize the Hugging Face text generation pipeline with BlenderBot
|
| 9 |
+
conversational_pipeline = pipeline('text-generation', model='facebook/blenderbot-3B')
|
| 10 |
|
| 11 |
def tailor_with_langsmith(model_data):
|
| 12 |
headers = {
|
|
|
|
| 22 |
|
| 23 |
def create_custom_conversation(prompt):
|
| 24 |
# Step 1: Get response from Hugging Face model
|
| 25 |
+
hf_response = conversational_pipeline(prompt, max_length=50) # Adjust max_length as needed
|
| 26 |
hf_reply = hf_response[0]['generated_text']
|
| 27 |
|
| 28 |
# Step 2: Tailor the response using LangSmith
|
| 29 |
+
tailored_response = tailor_with_langsmith({'model_data': hf_reply})
|
| 30 |
tailored_reply = tailored_response.get('tailored_reply', '')
|
| 31 |
|
| 32 |
return tailored_reply
|