Skip to content

Commit 5765d79

Browse files
author
kwisznie
committed
temporaru
1 parent 70cd673 commit 5765d79

File tree

4 files changed

+31
-39
lines changed

4 files changed

+31
-39
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ A magical AI that turns your boring long documents into... slightly less boring
2929

3030
It doesn't work, we used the wrong AI :( and Azure for Students doesn't let us access the OpenAI model.
3131

32-
We can only use a special model to summarize text files, but this Azure service just copies and pastes random sentences from our text.
32+
We can only use a special model to summarize text files, but this Azure service just copies and pastes random sentences from our text.
3333
```ini
3434
AZURE_ENDPOINT='https://kaka-doc-summary-ai.cognitiveservices.azure.com/'
3535
AZURE_API_KEY='your-magic-code-here'
@@ -61,3 +61,12 @@ streamlit run app/main.py # Do the thing
6161
- Azure for the free(ish) toys
6262
- My cat for moral support 🐈
6363
- Coffee ☕ (the real MVP)
64+
65+
66+
# Nowego gowno
67+
## env file
68+
```ini
69+
API_KEY='api'
70+
BASE_URL='https://openrouter.ai/api/v1'
71+
MODEL='mistralai/mistral-small-3.1-24b-instruct:free'
72+
```

app/src/summarizer.py

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,31 @@
1-
from azure.core.credentials import AzureKeyCredential
2-
from azure.ai.textanalytics import (
3-
TextAnalyticsClient,
4-
ExtractiveSummaryAction
5-
)
1+
from openai import OpenAI
62
from config.settings import Settings
73

84
class Summarizer:
95
def __init__(self, config: Settings):
10-
self.endpoint = config.AZURE_ENDPOINT
11-
self.key = config.AZURE_API_KEY
12-
self.client = TextAnalyticsClient(
13-
endpoint=self.endpoint,
14-
credential=AzureKeyCredential(self.key)
6+
self.api_key = config.API_KEY
7+
self.base_url = config.BASE_URL
8+
self.model = config.MODEL
9+
self.client = OpenAI(
10+
base_url=self.base_url,
11+
api_key=self.api_key,
1512
)
1613

1714
def summarize(self, text: str) -> str:
1815
try:
19-
actions = [
20-
ExtractiveSummaryAction(
21-
max_sentence_count=15,
22-
order_by="Rank"
23-
)
24-
]
25-
26-
poller = self.client.begin_analyze_actions(
27-
documents=[text],
28-
actions=actions,
29-
language="pl",
30-
show_stats=True
16+
completion = self.client.chat.completions.create(
17+
model = self.model,
18+
messages=[
19+
{
20+
"role": "user",
21+
"content": f"Summarize this text in the same language:\n\n{text}"
22+
}
23+
]
3124
)
3225

33-
results = list(poller.result())
34-
35-
summary_sentences = []
36-
for result in results:
37-
for action_result in result:
38-
if not action_result.is_error:
39-
summary_sentences.extend(
40-
sentence.text for sentence in action_result.sentences
41-
)
26+
result = completion.choices[0].message.content
4227

43-
return " ".join(summary_sentences) if summary_sentences else "No summary generated"
28+
return result
4429

4530
except Exception as e:
4631
raise Exception(f"Summarization error: {str(e)}")

config/settings.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
class Settings:
66
def __init__(self):
77
load_dotenv(dotenv_path=Path(".env"))
8-
self.AZURE_ENDPOINT = os.getenv("AZURE_ENDPOINT", "").strip()
9-
self.AZURE_API_KEY = os.getenv("AZURE_API_KEY", "")
10-
self.API_VERSION = os.getenv("API_VERSION", "2023-05-15")
11-
self.MAX_TOKENS = int(os.getenv("MAX_TOKENS", "1"))
8+
self.API_KEY = os.getenv("API_KEY", "")
9+
self.BASE_URL = os.getenv("BASE_URL", "")
10+
self.MODEL = os.getenv("MODEL", "")
1211

1312
settings = Settings()

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ dotenv
44
requests
55
typing
66
pytest
7-
azure-ai-textanalytics>=5.3.0
8-
azure-core>=1.28.0
7+
openai

0 commit comments

Comments
 (0)