-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate.py
More file actions
127 lines (105 loc) · 3.91 KB
/
Copy pathcreate.py
File metadata and controls
127 lines (105 loc) · 3.91 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "pinecone==9.1.0",
# "typer>=0.15.0",
# "rich>=13.0.0",
# ]
# ///
"""
Create a new Pinecone Assistant.
Usage:
uv run create.py --name ASSISTANT_NAME [--instructions TEXT] [--region us|eu] [--timeout SECONDS]
Environment Variables:
PINECONE_API_KEY: Required Pinecone API key
Output:
Success message with assistant details including host URL for MCP configuration
"""
import os
import typer
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
from pinecone import Pinecone
app = typer.Typer()
console = Console()
@app.command()
def main(
name: str = typer.Option(..., "--name", "-n", help="Unique name for the assistant"),
instructions: str = typer.Option(
"",
"--instructions",
"-i",
help="Instructions for assistant behavior (max 16KB)",
),
region: str = typer.Option(
"us",
"--region",
"-r",
help="Deployment region: 'us' or 'eu'",
),
timeout: int = typer.Option(
30,
"--timeout",
"-t",
help="Seconds to wait for ready status",
),
):
"""Create a new Pinecone Assistant for document Q&A with citations."""
# Validate region
if region not in ["us", "eu"]:
console.print("[red]Error: Region must be 'us' or 'eu'[/red]")
raise typer.Exit(1)
# Check for API key
api_key = os.environ.get("PINECONE_API_KEY")
if not api_key:
console.print("[red]Error: PINECONE_API_KEY environment variable not set[/red]")
console.print("\nGet your API key from: https://app.pinecone.io/?sessionType=signup")
raise typer.Exit(1)
try:
# Initialize Pinecone client
with console.status(f"[bold blue]Creating assistant '{name}'...[/bold blue]"):
pc = Pinecone(api_key=api_key, source_tag="cursor_plugin:assistant")
# Create assistant
assistant = pc.assistant.create_assistant(
assistant_name=name,
instructions=instructions if instructions else None,
region=region,
timeout=timeout,
metadata={"agentic-ide-source":"cursor-plugin"}
)
# Success message
console.print(f"\n[bold green]✓ Assistant '{name}' created successfully![/bold green]\n")
# Display assistant details in a table
table = Table(show_header=False, box=None)
table.add_column("Property", style="cyan")
table.add_column("Value", style="white")
table.add_row("Name", assistant.name)
table.add_row("Region", region)
table.add_row("Status", f"[yellow]{assistant.status}[/yellow]")
table.add_row("Host", getattr(assistant, "host", "N/A"))
if instructions:
instructions_preview = instructions[:80] + "..." if len(instructions) > 80 else instructions
table.add_row("Instructions", instructions_preview)
console.print(table)
# MCP configuration info
host = getattr(assistant, "host", "")
if host:
mcp_info = f"""[bold]MCP Endpoint:[/bold]
{host}/mcp/assistants/{name}
[bold]Set environment variable:[/bold]
export PINECONE_ASSISTANT_HOST="{host}"
"""
console.print(Panel(mcp_info, title="MCP Configuration", border_style="blue"))
# Next steps
next_steps = f"""[bold]Next steps:[/bold]
1. Upload files: [cyan]uv run upload.py --assistant {name} --source PATH[/cyan]
2. Chat: [cyan]uv run chat.py --assistant {name} --message "YOUR QUESTION"[/cyan]
3. Get context: [cyan]uv run context.py --assistant {name} --query "SEARCH TEXT"[/cyan]"""
console.print(Panel(next_steps, title="What's Next?", border_style="green"))
except Exception as e:
console.print(f"[red]Error creating assistant: {e}[/red]")
raise typer.Exit(1)
if __name__ == "__main__":
app()