Skip to content

Commit 4d31f88

Browse files
authored
Merge pull request #2 from Shared-Pointer/implementation_podejscie2
IMPLEMENTATOR v1.1
2 parents 70cd673 + ebe744e commit 4d31f88

File tree

5 files changed

+36
-63
lines changed

5 files changed

+36
-63
lines changed

README.md

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,26 @@ A magical AI that turns your boring long documents into... slightly less boring
77

88
---
99

10-
## ~~🧙‍♂️ Abra-kadabra Setup (Azure Edition)~~
10+
## 🧞‍♂️ OpenRouter Vibes (Free Magic Edition)
1111

12-
### ~~Numero uno - Azure Voodoo~~
13-
1. ~~Get your student 🎓 email ready~~
14-
2. ~~Go to [Azure Portal](https://portal.azure.com) (yes, the cloud place)~~
15-
3. ~~Type `Language Service` like you're summoning a demon 🔮~~
12+
### Numero uno - OpenRouter Shenanigans
13+
1. Create an account at [OpenRouter](https://openrouter.ai/) — yes, it’s real, and no, it's not a Wi-Fi company.
14+
2. Summon your **API key** from the shadows (or your [dashboard](https://openrouter.ai/account/keys)).
15+
3. Choose a model — for this silly quest, I picked [**Mistral Small 3.1 24B (free)**](https://openrouter.ai/mistralai/mistral-small-3.1-24b-instruct:free) because it sounds fancy.
16+
4. Pick the **Free plan** — because we’re broke but curious.
17+
5. Browse other free models if you feel spicy 🌶️ — this one’s just a humble suggestion.
1618

17-
### ~~Numero dos - Resource Goofin'~~
18-
~~Fill this bad boy like:~~
19-
- ~~**Subscription**: "Azure for Students" (the free candy 🍭)~~
20-
- ~~**Resource group**: `AI-Document-Summary` (or whatever)~~
21-
- ~~**Region**: West Europe 🌍 (or pick your favorite)~~
22-
- ~~**Name**: `kaka-doc-summary-ai` (mandatory "kaka" prefix)~~
23-
- ~~**Pricing tier**: F0 (aka "please don't charge me" mode)~~
19+
### Numero dos - The Sacred `.env` Scrolls 🧻
2420

25-
### ~~Numero tres - Secret Sauce 🕵️~~
26-
~~After Azure stops judging your life choices:~~
27-
1. ~~Go to "Keys and Endpoint" (sounds spy-ish)~~
28-
2. ~~Create `.env` file in `config/` with:~~
21+
Once you’ve tricked the system into trusting you, create a `.env` file inside `config/` (don’t ask, just do it).
2922

30-
It doesn't work, we used the wrong AI :( and Azure for Students doesn't let us access the OpenAI model.
31-
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.
3323
```ini
34-
AZURE_ENDPOINT='https://kaka-doc-summary-ai.cognitiveservices.azure.com/'
35-
AZURE_API_KEY='your-magic-code-here'
36-
API_VERSION='2023-04-01'
37-
MAX_TOKENS=1000
24+
API_KEY='your-api-key-here' # secret sauce
25+
BASE_URL='https://openrouter.ai/api/v1' # the mothership
26+
MODEL='mistralai/mistral-small-3.1-24b-instruct:free' # free = best flavor
3827
```
3928

29+
4030
## 🚀 Launch Protocol (for dummies)
4131
### Option A: Docker Magic 🐳
4232
```
@@ -60,4 +50,4 @@ streamlit run app/main.py # Do the thing
6050
## 🎉 Special Thanks
6151
- Azure for the free(ish) toys
6252
- My cat for moral support 🐈
63-
- Coffee ☕ (the real MVP)
53+
- Coffee ☕ (the real MVP)

app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def main():
3333
summarizzler = Summarizer(settings)
3434
result = summarizzler.summarize(fileProcessor.get_content())
3535
with st.spinner("Summarizing your doc...."):
36-
time.sleep(5)
36+
time.sleep(1)
3737
st.success("Your summary is ready:")
3838
st.markdown(result)
3939

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:\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)