Spaces:
Runtime error
Runtime error
| from openai import OpenAI | |
| import json | |
| class Analyzer: | |
| def __init__(self, base_url, api_key): | |
| self.client = OpenAI( | |
| base_url=base_url, | |
| api_key=api_key | |
| ) | |
| def analyze(self, query, search_results): | |
| """ | |
| Analyze search results using the custom LLM | |
| """ | |
| # Prepare context from search results | |
| context = "\n\n".join([ | |
| f"Source: {result.get('url', 'N/A')}\nContent: {result.get('content', '')}" | |
| for result in search_results[:3] # Limit to top 3 for context | |
| ]) | |
| prompt = f""" | |
| You are an expert research analyst. Analyze the following query and information to provide a comprehensive summary. | |
| Query: {query} | |
| Information: | |
| {context} | |
| Please provide: | |
| 1. A brief overview of the topic | |
| 2. Key findings or developments | |
| 3. Different perspectives or approaches | |
| 4. Potential implications or future directions | |
| 5. Any controversies or conflicting viewpoints | |
| Structure your response clearly with these sections. | |
| """ | |
| try: | |
| response = self.client.chat.completions.create( | |
| model="DavidAU/OpenAi-GPT-oss-20b-abliterated-uncensored-NEO-Imatrix-gguf", | |
| messages=[ | |
| {"role": "system", "content": "You are a helpful research assistant that provides structured, analytical responses."}, | |
| {"role": "user", "content": prompt} | |
| ], | |
| temperature=0.7, | |
| max_tokens=1500, | |
| stream=False | |
| ) | |
| return response.choices[0].message.content | |
| except Exception as e: | |
| return f"Analysis failed: {str(e)}" | |