Skip to content

[Doc Improvement][Code snippet CSharp Python] #12933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions msteams-platform/bots/how-to/bot-messages-ai-generated-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ If you're using **Teams AI library** to build your bot, citations are added to a

If you're using **Bot Framework SDK** to build your bot, include `citation` under the `entities` array. Following is an example code snippet:

# [JavaScript](#tab/js)

```javascript
await context.sendActivity({
type: ActivityTypes.Message,
Expand Down Expand Up @@ -200,6 +202,77 @@ await context.sendActivity({
})
```

# [Python](#tab/python)

```python
@app.message("citation")
async def on_message(context: TurnContext, state: TurnState):
appearance = Appearance(
name="Understanding AI Citations in Python",
abstract=snippet("A brief extract demonstrating the integration of AI Citations in Python.", 477),
url="https://example.com/py-ai-citations",
keywords=["Python", "Citations"],
image=AppearanceImage(name="Microsoft Excel"),
usage_info=SensitivityUsageInfo(
name="Creative Work",
description="Sensitive content information for Python AI citation.",
position=1,
pattern= Pattern(
in_defined_term_set= "ColorSet",
name= "Red",
term_code= "#FF0000")
)
)

# Create the client citation with a specific position and the defined appearance.
citation = ClientCitation(
position=1,
appearance=appearance
)

# Create the AIEntity, including the citation and overall sensitivity usage information.
ai_entity = AIEntity(
additional_type=["AIGeneratedContent"],
citation=[citation],
usage_info=SensitivityUsageInfo(
name="Creative Work",
description="Overall message sensitivity information for AI citations.",
position=1,
pattern=Pattern(
in_defined_term_set="ColorSet",
name= "Red",
term_code="#FF0000",
)
)
)

# Use the helper function to format citation tags within a sample message.
sample_text = "This is an AI-generated message with citation [doc1]."
formatted_text = format_citations_response(sample_text)
print("Formatted Text:", formatted_text)

# Retrieve citations used in the formatted text.
used_citations = get_used_citations(formatted_text, [citation])
print("Used Citations:", used_citations)
print("AI Entity:", ai_entity)
await context.send_activity(
Activity(
type=ActivityTypes.message,
text=formatted_text,
entities=[
AIEntity(
citation=(list(used_citations) if used_citations else []),
additional_type=["AIGeneratedContent"],
),
],
)
)

return True
```

---

| Property | Type | Required | Description |
|--|--|--|--|
| `citation` | Object | ✔️ | Details of the citation. |
Expand Down