Setting the file. One moment. Create · Pinecone Assistant · pinecone-io/skills · Skills Docs(opens in a new tab)
scripts/create.py
Python·125 lines·4 KB
PINECONE_API_KEY: Required Pinecone API key
18
19Output:
20 Success message with assistant details including host URL for MCP configuration
21"""
22
23import os
24import typer
25from rich.console import Console
26from rich.panel import Panel
27from rich.table import Table
28from pinecone import Pinecone
29
30app = typer.Typer()
31console = Console()
32
33
34@app.command()
35def main(
36 name: str = typer.Option(..., "--name", "-n", help="Unique name for the assistant"),
37 instructions: str = typer.Option(
38 "",
39 "--instructions",
40 "-i",
41 help="Instructions for assistant behavior (max 16KB)",
42 ),
43 region: str = typer.Option(
44 "us",
45 "--region",
46 "-r",
47 help="Deployment region: 'us' or 'eu'",
48 ),
49 timeout: int = typer.Option(
50 30,
51 "--timeout",
52 "-t",
53 help="Seconds to wait for ready status",
54 ),
55):
56 """Create a new Pinecone Assistant for document Q&A with citations."""
57
58 # Validate region
59 if region not in ["us", "eu"]:
60 console.print("[red]Error: Region must be 'us' or 'eu'[/red]")
61 raise typer.Exit(1)
62
63 # Check for API key
64 api_key = os.environ.get("PINECONE_API_KEY")
65 if not api_key:
66 console.print("[red]Error: PINECONE_API_KEY environment variable not set[/red]")
67 console.print("\nGet your API key from: https://app.pinecone.io/?sessionType=signup")
68 raise typer.Exit(1)
69
70 try:
71 # Initialize Pinecone client
72 with console.status(f"[bold blue]Creating assistant '{name}'...[/bold blue]"):
73 pc = Pinecone(api_key=api_key, source_tag="pinecone_skills:assistant")
74
75 # Create assistant
76 assistant = pc.assistant.create_assistant(
77 assistant_name=name,
78 instructions=instructions if instructions else None,
79 region=region,
80 timeout=timeout,
81 metadata={"agentic-ide-source":"pinecone-skills"}
82 )
83
84 # Success message
85 console.print(f"\n[bold green]✓ Assistant '{name}' created successfully![/bold green]\n")
86
87 # Display assistant details in a table
88 table = Table(show_header=False, box=None)
89 table.add_column("Property", style="cyan")
90 table.add_column("Value", style="white")
91
92 table.add_row("Name", assistant.name)
93 table.add_row("Region", region)
94 table.add_row("Status", f"[yellow]{assistant.status}[/yellow]")
95 table.add_row("Host", getattr(assistant, "host", "N/A"))
96 if instructions:
97 instructions_preview = instructions[:80] + "..." if len(instructions) > 80 else instructions
98 table.add_row("Instructions", instructions_preview)
99
100 console.print(table)
101
102 # MCP configuration info
103 host = getattr(assistant, "host", "")
104 if host:
105 mcp_info = f"""[bold]MCP Endpoint:[/bold]
106{host}/mcp/assistants/{name}
107
108[bold]Set environment variable:[/bold]
109export PINECONE_ASSISTANT_HOST="{host}"
110"""
111 console.print(Panel(mcp_info, title="MCP Configuration", border_style="blue"))
112
113 # Next steps
114 next_steps = f"""[bold]Next steps:[/bold]
115<<next_after_create>>"""
116
117 console.print(Panel(next_steps, title="What's Next?", border_style="green"))
118
119 except Exception as e:
120 console.print(f"[red]Error creating assistant: {e}[/red]")
121 raise typer.Exit(1)
122
123
124if __name__ == "__main__":
125 app()