ใช้ SDK นี้เพื่อสร้างแอปพลิเคชันที่ขับเคลื่อนโดย Watson ใน Unity
ในเวอร์ชันหลักนี้ 6.0.0 Tone Analyzer API ได้ถูกลบออกเพื่อเตรียมพร้อมสำหรับการเลิกใช้งาน หากคุณต้องการใช้ SDK นี้ต่อไปเพื่อเรียก Tone Analyzer จนกว่าจะมีการเลิกใช้งานครั้งสุดท้าย คุณจะต้องใช้เวอร์ชันก่อนหน้า เมื่อวันที่ 24 กุมภาพันธ์ พ.ศ. 2565 IBM ประกาศเลิกใช้งานบริการ Tone Analyzer บริการนี้จะไม่สามารถใช้ได้อีกต่อไปในวันที่ 24 กุมภาพันธ์ 2023 ตั้งแต่วันที่ 24 กุมภาพันธ์ 2022 คุณจะไม่สามารถสร้างอินสแตนซ์ใหม่ได้ อินสแตนซ์ที่มีอยู่จะได้รับการสนับสนุนจนถึงวันที่ 24 กุมภาพันธ์ 2023
อีกทางเลือกหนึ่ง เราขอแนะนำให้คุณพิจารณาย้ายไปยังบริการ Natural Languageความเข้าใจบน IBM Cloud ด้วยความเข้าใจภาษาธรรมชาติ การวิเคราะห์น้ำเสียงทำได้โดยใช้แบบจำลองการจำแนกประเภทที่สร้างไว้ล่วงหน้า ซึ่งมอบวิธีง่ายๆ ในการตรวจจับน้ำเสียงของภาษาในข้อความที่เป็นลายลักษณ์อักษร สำหรับข้อมูลเพิ่มเติม โปรดดูที่ การย้ายจากจุดสิ้นสุดการมีส่วนร่วมของลูกค้า Watson Tone Analyzer ไปเป็นความเข้าใจภาษาธรรมชาติ
ในเวอร์ชันหลักนี้ 6.0.0 NLC API ได้ถูกลบออกเพื่อเตรียมพร้อมสำหรับการเลิกใช้งาน หากคุณต้องการใช้ SDK นี้ต่อไปเพื่อโทรไปยัง NLC จนกว่าจะมีการเลิกใช้งานครั้งสุดท้าย คุณจะต้องใช้เวอร์ชันก่อนหน้า เมื่อวันที่ 9 สิงหาคม 2021 IBM ประกาศเลิกใช้งานบริการ Natural Language Classifier บริการนี้จะไม่สามารถใช้ได้อีกต่อไปตั้งแต่วันที่ 8 สิงหาคม 2022 ตั้งแต่วันที่ 9 กันยายน 2021 คุณจะไม่สามารถสร้างอินสแตนซ์ใหม่ได้ อินสแตนซ์ที่มีอยู่จะได้รับการสนับสนุนจนถึงวันที่ 8 สิงหาคม 2022 อินสแตนซ์ใดๆ ที่ยังคงมีอยู่ในวันดังกล่าวจะถูกลบ
อีกทางเลือกหนึ่ง เราขอแนะนำให้คุณพิจารณาย้ายไปยังบริการการทำความเข้าใจภาษาธรรมชาติบน IBM Cloud ที่ใช้การเรียนรู้เชิงลึกเพื่อดึงข้อมูลและข้อมูลเชิงลึกจากข้อความ เช่น คำสำคัญ หมวดหมู่ ความรู้สึก อารมณ์ และไวยากรณ์ พร้อมด้วยข้อความหลายป้ายกำกับขั้นสูง ความสามารถในการจำแนกประเภท เพื่อให้ข้อมูลเชิงลึกที่สมบูรณ์ยิ่งขึ้นสำหรับธุรกิจหรืออุตสาหกรรมของคุณ สำหรับข้อมูลเพิ่มเติม โปรดดูที่ การย้ายไปสู่ความเข้าใจภาษาธรรมชาติ
URL ตำแหน่งข้อมูล Watson API ที่ watsonplatform.net มีการเปลี่ยนแปลงและจะไม่ทำงานหลังจากวันที่ 26 พฤษภาคม 2021 อัปเดตการเรียกใช้ของคุณเพื่อใช้ URL ตำแหน่งข้อมูลใหม่ สำหรับข้อมูลเพิ่มเติม โปรดดู https://cloud.ibm.com/docs/watson?topic=watson-endpoint-change
ตรวจสอบให้แน่ใจว่าคุณมีข้อกำหนดเบื้องต้นต่อไปนี้:
การอัปเดต MacOS เป็น Mojave อาจปิดใช้งานไมโครโฟนสำหรับ Unity หากคุณประสบปัญหานี้ โปรดดูหลักเกณฑ์เหล่านี้เพื่อกำหนดค่าไมโครโฟนสำหรับ Mojave
คุณสามารถรับ SDK รุ่นล่าสุดได้โดยคลิกที่นี่ คุณจะต้องดาวน์โหลด IBM Unity SDK Core รุ่นล่าสุดโดยคลิกที่นี่
ย้ายไดเรกทอรี unity-sdk
และ unity-sdk-core
ไปยังไดเรกทอรี Assets
ของโปรเจ็กต์ Unity ของคุณ ทางเลือก: เปลี่ยนชื่อไดเร็กทอรี SDK จาก unity-sdk
เป็น Watson
และไดเร็กทอรี Core จาก unity-sdk-core
เป็น IBMSdkCore
หากต้องการสร้างอินสแตนซ์ของบริการ Watson และข้อมูลประจำตัว ให้ทำตามขั้นตอนด้านล่าง
หมายเหตุ: ข้อมูลรับรองบริการแตกต่างจากชื่อผู้ใช้และรหัสผ่านบัญชี IBM Cloud ของคุณ
ข้อมูลรับรองสำหรับแต่ละบริการประกอบด้วย username
password
และ url
ปลายทาง หรือ apikey
และ url
ปลายทาง
คำเตือน: คุณมีหน้าที่รับผิดชอบในการรักษาความปลอดภัยข้อมูลประจำตัวของคุณเอง ผู้ใช้ที่มีข้อมูลประจำตัวบริการของคุณสามารถเข้าถึงอินสแตนซ์บริการของคุณได้!
หากต้องการเริ่มต้นใช้งาน Watson Service ใน Unity โปรดไปที่ลิงก์เพื่อดูโค้ด
บริการ Watson กำลังย้ายไปยังการตรวจสอบสิทธิ์ Identity and Access Management (IAM) ที่ใช้โทเค็น
หากต้องการค้นหาว่าจะใช้การรับรองความถูกต้องแบบใด ให้ดูข้อมูลรับรองบริการ คุณพบข้อมูลรับรองบริการสำหรับการรับรองความถูกต้องในลักษณะเดียวกันสำหรับบริการ Watson ทั้งหมด:
url
และ apikey
หรือ username
และ password
ในโค้ดของคุณ คุณสามารถใช้ค่าเหล่านี้ในตัวสร้างบริการหรือด้วยการเรียกใช้เมธอดหลังจากสร้างอินสแตนซ์ของบริการของคุณแล้ว
บริการบางอย่างใช้การตรวจสอบสิทธิ์ Identity and Access Management (IAM) โดยใช้โทเค็น การตรวจสอบสิทธิ์ IAM ใช้คีย์ API ของบริการเพื่อรับโทเค็นการเข้าถึงที่ส่งผ่านการโทร โทเค็นการเข้าถึงใช้งานได้ประมาณหนึ่งชั่วโมงและต้องสร้างใหม่
คุณระบุ คีย์ API ของบริการ IAM หรือ โทเค็นการเข้าถึง :
HasIamTokenData()
จะส่งคืน true
Authenticator authenticator ;
AssistantService assistant ;
string versionDate = "<service-version-date>" ;
IEnumerator TokenExample ( )
{
// Create authenticator using the IAM token options
authenticator = new IamAuthenticator ( apikey : "<iam-api-key>" ) ;
while ( ! authenticator . CanAuthenticate ( ) )
yield return null ;
assistant = new AssistantService ( versionDate , authenticator ) ;
assistant . SetServiceUrl ( "<service-url>" ) ;
assistant . ListWorkspaces ( callback : OnListWorkspaces ) ;
}
private void OnListWorkspaces ( DetailedResponse < WorkspaceCollection > response , IBMError error )
{
Log . Debug ( "OnListWorkspaces()" , "Response: {0}" , response . Response ) ;
}
Authenticator authenticator ;
AssistantService assistant ;
string versionDate = "<service-version-date>" ;
void TokenExample ( )
{
// Create authenticator using the Bearer Token
authenticator = new BearerTokenAuthenticator ( "<bearer-token>" ) ;
assistant = new AssistantService ( versionDate , authenticator ) ;
assistant . SetServiceUrl ( "<service-url>" ) ;
assistant . ListWorkspaces ( callback : OnListWorkspaces ) ;
}
private void OnListWorkspaces ( DetailedResponse < WorkspaceCollection > response , IBMError error )
{
Log . Debug ( "OnListWorkspaces()" , "Response: {0}" , response . Response ) ;
}
Authenticator authenticator ;
AssistantService assistant ;
string versionDate = "<service-version-date>" ;
void UsernamePasswordExample ( )
{
Authenticator authenticator = new BasicAuthenticator ( "<username>" , "<password>" , "<url>" ) ;
assistant = new AssistantService ( versionDate , authenticator ) ;
assistant . SetServiceUrl ( "<service-url>" ) ;
}
มีสองวิธีในการจัดหาตัวตรวจสอบความถูกต้องที่คุณพบด้านบนให้กับ SDK สำหรับการตรวจสอบสิทธิ์
ด้วยไฟล์ข้อมูลรับรอง คุณเพียงแค่ต้องวางไฟล์ในตำแหน่งที่ถูกต้อง จากนั้น SDK จะดำเนินการแยกวิเคราะห์และรับรองความถูกต้อง คุณสามารถรับไฟล์นี้ได้โดยคลิกปุ่ม ดาวน์โหลด สำหรับข้อมูลประจำตัวในแท็บ จัดการ ของอินสแตนซ์บริการของคุณ
ไฟล์ที่ดาวน์โหลดจะถูกเรียกว่า ibm-credentials.env
นี่คือชื่อที่ SDK จะค้นหาและ จะต้อง คงไว้ เว้นแต่ว่าคุณต้องการกำหนดค่าเส้นทางของไฟล์ (จะมีข้อมูลเพิ่มเติมในภายหลัง) SDK จะค้นหาไฟล์ ibm-credentials.env
ในตำแหน่งต่อไปนี้ (ตามลำดับ):
ตราบใดที่คุณตั้งค่าอย่างถูกต้อง คุณก็ไม่ต้องกังวลกับการตั้งค่าตัวเลือกการรับรองความถูกต้องในโค้ดของคุณ ตัวอย่างเช่น หากคุณสร้างและดาวน์โหลดไฟล์ข้อมูลประจำตัวสำหรับอินสแตนซ์ Discovery ของคุณ คุณเพียงแค่ต้องทำสิ่งต่อไปนี้:
public IEnumerator ExampleAutoService ( )
{
Assistant assistantService = new Assistant ( "2019-04-03" ) ;
// Wait for authorization token
while ( ! assistantService . Authenticator . CanAuthenticate ( ) )
yield return null ;
var listWorkspacesResult = assistantService . ListWorkspaces ( ) ;
}
แค่นั้นแหละ!
หากคุณใช้บริการมากกว่าหนึ่งบริการในโค้ดของคุณและได้รับไฟล์ ibm-credentials.env
สองไฟล์ที่แตกต่างกัน เพียงรวมเนื้อหาเข้าด้วยกันในไฟล์ ibm-credentials.env
ไฟล์เดียว จากนั้น SDK จะจัดการการกำหนดตัวตรวจสอบสิทธิ์ให้กับบริการที่เหมาะสม .
หากคุณต้องการกำหนดค่าตำแหน่ง/ชื่อของไฟล์หนังสือรับรองของคุณ คุณสามารถตั้งค่าตัวแปรสภาพแวดล้อมที่เรียกว่า IBM_CREDENTIALS_FILE
ซึ่งจะมีความสำคัญเหนือกว่าสถานที่ที่ระบุไว้ข้างต้น ต่อไปนี้คือวิธีที่คุณสามารถทำได้:
export IBM_CREDENTIALS_FILE= " <path> "
โดยที่ <path>
/home/user/Downloads/<file_name>.env
เป็นสิ่งที่ชอบ
หากคุณต้องการตั้งค่าการตรวจสอบสิทธิ์ด้วยตนเองในโค้ดของคุณ SDK ก็รองรับเช่นกัน วิธีที่คุณจะทำเช่นนี้ขึ้นอยู่กับประเภทของตัวตรวจสอบสิทธิ์ที่อินสแตนซ์บริการของคุณมอบให้
จำเป็นต้องมีการติดต่อกลับสำเร็จ คุณสามารถระบุประเภทการส่งคืนในการโทรกลับ
AssistantService assistant ;
string assistantVersionDate = "<assistant-version-date>" ;
Authenticator assistantAuthenticator ;
string workspaceId = "<workspaceId>" ;
DiscoveryService discovery ;
string discoveryVersionDate = "<discovery-version-date>" ;
Authenticator discoveryAuthenticator ;
private void Example ( )
{
assistant = new AssistantService ( assistantVersionDate , assistantAuthenticator ) ;
assistant . SetServiceUrl ( "<service-url>" ) ;
discovery = new DiscoveryService ( discoveryVersionDate , discoveryAuthenticator ) ;
discovery . SetServiceUrl ( "<service-url>" ) ;
// Call with sepcific callbacks
assistant . Message (
callback : OnMessage ,
workspaceId : workspaceId
) ;
discovery . ListEnvironments (
callback : OnGetEnvironments
) ;
}
private void OnMessage ( DetailedResponse < MessageResponse > response , IBMError error )
{
Log . Debug ( "ExampleCallback.OnMessage()" , "Response received: {0}" , response . Response ) ;
}
private void OnGetEnvironments ( DetailedResponse < ListEnvironmentsResponse > response , IBMError error )
{
Log . Debug ( "ExampleCallback.OnGetEnvironments()" , "Response received: {0}" , response . Response ) ;
}
เนื่องจากลายเซ็นการเรียกกลับที่สำเร็จเป็นแบบทั่วไป และการเรียกกลับที่ล้มเหลวจะมีลายเซ็นเดียวกันเสมอ คุณจึงสามารถใช้ชุดการเรียกกลับชุดเดียวเพื่อจัดการกับการโทรหลายสายได้
AssistantService assistant ;
string assistantVersionDate = "<assistant-version-date>" ;
Authenticator assistantAuthenticator ;
string workspaceId = "<workspaceId>" ;
DiscoveryService discovery ;
string discoveryVersionDate = "<discovery-version-date>" ;
Authenticator discoveryAuthenticator ;
private void Example ( )
{
assistant = new AssistantService ( assistantVersionDate , assistantAuthenticator ) ;
assistant . SetServiceUrl ( "<service-url>" ) ;
// Call with generic callbacks
JObject input = new JObject ( ) ;
input . Add ( "text" , "" ) ;
assistant . Message (
callback : OnSuccess ,
workspaceId : workspaceId ,
input : input
) ;
discovery = new DiscoveryService ( discoveryVersionDate , discoveryAuthenticator ) ;
discovery . SetServiceUrl ( "<service-url>" ) ;
discovery . ListEnvironments (
callback : OnSuccess
) ;
}
// Generic success callback
private void OnSuccess < T > ( DetailedResponse < T > resp , IBMError error )
{
Log . Debug ( "ExampleCallback.OnSuccess()" , "Response received: {0}" , resp . Response ) ;
}
คุณยังสามารถใช้การโทรกลับโดยไม่ระบุชื่อได้
AssistantService assistant ;
string assistantVersionDate = "<assistant-version-date>" ;
Authenticator assistantAuthenticator ;
string workspaceId = "<workspaceId>" ;
private void Example ( )
{
assistant = new AssistantService ( assistantVersionDate , assistantAuthenticator ) ;
assistant . ListWorkspaces (
callback : ( DetailedResponse < WorkspaceCollection > response , IBMError error ) =>
{
Log . Debug ( "ExampleCallback.OnSuccess()" , "ListWorkspaces result: {0}" , response . Response ) ;
} ,
pageLimit : 1 ,
includeCount : true ,
sort : "-name" ,
includeAudit : true
) ;
assistant . SetServiceUrl ( "<service-url>" ) ;
}
คุณสามารถตรวจสอบการตอบสนอง error
เพื่อดูว่ามีข้อผิดพลาดในการโทรหรือไม่
AssistantService assistant ;
string assistantVersionDate = "<assistant-version-date>" ;
Authenticator assistantAuthenticator ;
string workspaceId = "<workspaceId>" ;
private void Example ( )
{
assistant = new AssistantService ( versionDate , authenticator ) ;
assistant . Message ( OnMessage , workspaceId ) ;
}
private void OnMessage ( DetailedResponse < MessageResponse > response , IBMError error )
{
if ( error == null )
{
Log . Debug ( "ExampleCallback.OnMessage()" , "Response received: {0}" , response . Response ) ;
}
else
{
Log . Debug ( "ExampleCallback.OnMessage()" , "Error received: {0}, {1}, {3}" , error . StatusCode , error . ErrorMessage , error . Response ) ;
}
}
คุณสามารถส่งส่วนหัวคำขอที่กำหนดเองได้โดยเพิ่มลงในบริการ
AssistantService assistant ;
string assistantVersionDate = "<assistant-version-date>" ;
Authenticator assistantAuthenticator ;
string workspaceId = "<workspaceId>" ;
void Example ( )
{
assistant = new AssistantService ( assistantVersionDate , assistantAuthenticator ) ;
// Add custom header to the REST call
assistant . WithHeader ( "X-Watson-Metadata" , "customer_id=some-assistant-customer-id" ) ;
assistant . Message ( OnSuccess , "<workspace-id>" ) ;
}
private void OnSuccess ( DetailedResponse < MessageResponse > response , IBMError error )
{
Log . Debug ( "ExampleCallback.OnMessage()" , "Response received: {0}" , response . Response ) ;
}
คุณสามารถรับส่วนหัวการตอบกลับได้ในวัตถุ headers
ใน DetailedResponse
AssistantService assistant ;
string assistantVersionDate = "<assistant-version-date>" ;
Authenticator assistantAuthenticator ;
string workspaceId = "<workspaceId>" ;
void Example ( )
{
assistant = new AssistantService ( assistantVersionDate , assistantAuthenticator ) ;
assistant . Message ( OnMessage , "<workspace-id>" ) ;
}
private void OnMessage ( DetailedResponse < MessageResponse > response , IBMError error )
{
// List all headers in the response headers object
foreach ( KeyValuePair < string , object > kvp in response . Headers )
{
Log . Debug ( "ExampleCustomHeader.OnMessage()" , "{0}: {1}" , kvp . Key , kvp . Value ) ;
}
}
การเรียก SDK ทุกครั้งจะส่งคืนการตอบกลับด้วยรหัสธุรกรรมในส่วนหัว X-Global-Transaction-Id
รหัสนี้เมื่อรวมภูมิภาคอินสแตนซ์บริการเข้าด้วยกันจะช่วยให้ทีมสนับสนุนแก้ไขปัญหาจากบันทึกที่เกี่ยวข้อง
public void ExampleGetTransactionId ( )
{
AssistantService service = new AssistantService ( "{version-date}" ) ;
service . ListWorkspaces (
callback : ( DetailedResponse < Workspace > response , IBMError error ) =>
{
if ( error != null )
{
Log . Debug ( "AssistantServiceV1" , "Transaction Id: {0}" , error . ResponseHeaders [ "X-Global-Transaction-Id" ] ) ;
}
else
{
Log . Debug ( "AssistantServiceV1" , "Transaction Id: {0}" , response . Headers [ "X-Global-Transaction-Id" ] ) ;
}
}
) ;
}
อย่างไรก็ตาม รหัสธุรกรรมจะไม่พร้อมใช้งานเมื่อ API ไม่ตอบกลับด้วยเหตุผลบางประการ ในกรณีนั้น คุณสามารถตั้งค่ารหัสธุรกรรมของคุณเองในคำขอได้ ตัวอย่างเช่น แทนที่ <my-unique-transaction-id>
ในตัวอย่างต่อไปนี้ด้วยรหัสธุรกรรมที่ไม่ซ้ำกัน
public void ExampleSetTransactionId ( )
{
AssistantService service = new AssistantService ( "{version-date}" ) ;
service . WithHeader ( "X-Global-Transaction-Id" , "<my-unique-transaction-id>" ) ;
service . ListWorkspaces (
callback : ( DetailedResponse < Workspace > response , IBMError error ) =>
{
if ( error != null )
{
Log . Debug ( "AssistantServiceV1" , "Transaction Id: {0}" , error . ResponseHeaders [ "X-Global-Transaction-Id" ] ) ;
}
else
{
Log . Debug ( "AssistantServiceV1" , "Transaction Id: {0}" , response . Headers [ "X-Global-Transaction-Id" ] ) ;
}
}
) ;
}
บริการของ Watson ได้อัปเกรดโฮสต์เป็น TLS 1.2 สถานที่ตั้งในดัลลาสมีตำแหน่งข้อมูล TLS 1.0 ที่ใช้สำหรับการสตรีมได้ หากต้องการสตรีมในภูมิภาคอื่น ให้ใช้ Unity 2018.2 และตั้งค่า Scripting Runtime Version ในการตั้งค่า Build เป็น .NET 4.x equivalent
หากต้องการรองรับการแปลงคำพูดเป็นข้อความใน Unity เวอร์ชันก่อนหน้า ให้สร้างอินสแตนซ์ในตำแหน่งดัลลัส
คุณสามารถปิดใช้งานการยืนยัน SSL เมื่อทำการเรียกบริการ
AssistantService assistant ;
string assistantVersionDate = "<assistant-version-date>" ;
Authenticator assistantAuthenticator ;
string workspaceId = "<workspaceId>" ;
void Example ( )
{
authenticator . DisableSslVerification = true ;
assistant = new AssistantService ( assistantVersionDate , assistantAuthenticator ) ;
// disable ssl verification
assistant . DisableSslVerification = true ;
}
หากอินสแตนซ์บริการของคุณเป็น ICP4D ด้านล่างนี้คือสองวิธีในการเริ่มต้นบริการผู้ช่วย
username
, password
, icp4d_url
และ authentication_type
SDK จะจัดการโทเค็นสำหรับผู้ใช้
CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator ( "<url>" , "<username>" , "<password>" ) ;
while ( ! authenticator . CanAuthenticate ( ) )
{
yield return null ;
}
service = new AssistantService ( versionDate , authenticator ) ;
BearerTokenAuthenticator = new BearerTokenAuthenticator ( "<accessToken>" ) ;
while ( ! authenticator . CanAuthenticate ( ) )
{
yield return null ;
}
service = new AssistantService ( versionDate , authenticator ) ;
Watson Unity SDK ไม่รองรับ IBM Cloud Private เนื่องจาก UnityWebRequest ไม่รองรับการเชื่อมต่อผ่านพร็อกซี
สามารถดูเอกสารได้ที่นี่ คุณยังสามารถเข้าถึงเอกสารได้โดยเลือก API Reference เมนู Watson ( Watson -> API Reference )
คุณสามารถดูวิดีโอเริ่มต้นใช้งานสำหรับ IBM Watson SDK for Unity บน YouTube
หากคุณมีปัญหากับ API หรือมีคำถามเกี่ยวกับบริการ Watson โปรดดูที่ Stack Overflow
ค้นหาโปรเจ็กต์โอเพ่นซอร์สเพิ่มเติมบนเพจ IBM Github
ไลบรารีนี้ได้รับอนุญาตภายใต้ Apache 2.0 ข้อความลิขสิทธิ์ฉบับเต็มมีอยู่ใน LICENSE
ดูการมีส่วนร่วม.md
เราอยากจะเน้นโครงการโอเพ่นซอร์สเจ๋งๆ ที่ใช้ SDK นี้! หากคุณต้องการเพิ่มโครงการของคุณลงในรายการ โปรดสร้างปัญหาโดยเชื่อมโยงเราเข้ากับโครงการดังกล่าว