rashid01/tracker
0
1from transformers import pipeline2import requests3 4# Replace with your actual LangSmith API key5LANGSMITH_API_KEY = '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'6LANGSMITH_ENDPOINT = 'https://smith.langchain.com/o/b7d2cb3f-e589-52bb-9b8a-2e8483e4ee8d/tailor' # Make sure this is the correct endpoint7 8# Initialize the Hugging Face text generation pipeline with BlenderBot9conversational_pipeline = pipeline('text-generation', model='facebook/blenderbot-3B')10 11def tailor_with_langsmith(model_data):12 headers = {13 'Authorization': f'Bearer {LANGSMITH_API_KEY}',14 'Content-Type': 'application/json'15 }16 data = {17 'model_data': model_data18 }19 response = requests.post(LANGSMITH_ENDPOINT, json=data, headers=headers)20 response.raise_for_status()21 return response.json()22 23def create_custom_conversation(prompt):24 # Step 1: Get response from Hugging Face model25 hf_response = conversational_pipeline(prompt, max_length=50) # Adjust max_length as needed26 hf_reply = hf_response[0]['generated_text']27 28 # Step 2: Tailor the response using LangSmith29 tailored_response = tailor_with_langsmith({'model_data': hf_reply})30 tailored_reply = tailored_response.get('tailored_reply', '')31 32 return tailored_reply33 34if __name__ == '__main__':35 user_prompt = "Tell me about the latest advancements in AI."36 response = create_custom_conversation(user_prompt)37 print("Tailored Response:", response)38 