File: README.md

package info (click to toggle)
python-azure 20251118%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 783,356 kB
  • sloc: python: 6,474,533; ansic: 804; javascript: 287; sh: 205; makefile: 198; xml: 109
file content (71 lines) | stat: -rw-r--r-- 2,568 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
page_type: sample
languages:
  - python
products:
- azure
- azure-cognitive-services
- language-service
urlFragment: languagequestionanswering-samples
---

# Samples for Azure Language Question Answering (Inference)

These samples demonstrate how to use the runtime Question Answering features to query an existing knowledge base
or ad‑hoc text content. Authoring (project creation / deployment / source management) samples have been moved
to a separate location and are intentionally not referenced here.

## Samples Included

| File | Description |
|------|-------------|
| `sample_query_knowledgebase.py` / `async_samples/sample_query_knowledgebase_async.py` | Ask a question against a deployed knowledge base project (flattened parameters) |
| `sample_chat.py` / `async_samples/sample_chat_async.py` | Ask a follow‑up contextual question using `answer_context` |
| `sample_query_text.py` / `async_samples/sample_query_text_async.py` | Ask a question over ad‑hoc text documents (options object pattern) |

> Note: The deprecated wrapper methods `client.get_answers` and `client.get_answers_from_text`
> have been replaced in these samples by the recommended operations group access:
> `client.get_answers` and `client.get_answers_from_text`.

## Prerequisites

- Python 3.9+ (match the package's `python_requires`)
- An [Azure subscription][azure_subscription]
- A deployed Language Question Answering resource (project + deployment for knowledge base queries)

## Environment Variables

Set the following environment variables before running a sample:

Required (all runtime samples):
- `AZURE_QUESTIONANSWERING_ENDPOINT` – your resource endpoint
- `AZURE_QUESTIONANSWERING_KEY` – the API key

Additional for knowledge base & chat samples:
- `AZURE_QUESTIONANSWERING_PROJECT` – project (knowledge base) name
- `AZURE_QUESTIONANSWERING_DEPLOYMENT` – deployment name (if omitted, samples default to `production`)

## Install the Library

```bash
pip install azure-ai-language-questionanswering
```

## Run

```bash
python sample_query_knowledgebase.py
python sample_chat.py
python sample_query_text.py
# Async examples:
python async_samples/sample_query_knowledgebase_async.py
```

Ensure you are in this `samples` directory (or adjust paths accordingly).

## Authentication

These samples use `AzureKeyCredential`. For AAD / `DefaultAzureCredential` usage, see the main package documentation.

[azure_subscription]: https://azure.microsoft.com/free/
[language_service]: https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesTextAnalytics